in reply to print identical keys once along with their values

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $pair = qr{ (\d+) \s+ ([[:alpha:]]+) }xms; ;; my $record = '1 A 1 B 2 G 2 H 2 V'; ;; my %hash; while ($record =~ m{ \G \s* $pair }xmsg) { push @{ $hash{$1} }, $2; } dd \%hash; ;; $hash{$_} = join ':', @{$hash{$_}} for keys %hash; dd \%hash; " { 1 => ["A", "B"], 2 => ["G", "H", "V"] } { 1 => "A:B", 2 => "G:H:V" }