my @values = map { my $method = $_->[1]; sprintf "%s [$_->[0]]", format_name($_->[1]), $record->$method; } ( ['%s' => 'country'], ['%s' => 'region'], ['%s' => 'city'], ['%s' => 'postal_code'], ['%.4f' => 'latitude'], ['%.4f' => 'longitude'], ['%s' => 'time_zone'], ); my $command = sprintf('say IP: (%s) Hostname: [%s] %s', $ip, $hostname, join(' ', @values), ); say $command; # Xchat::command($command); sub format_name { return join ' ', map { ucfirst } split /_/, shift; }