in reply to print identical keys once along with their values

Actually, if you only want to output the data the way you've shown, then you could do it without nested data structure and use a simple hash (or a simple array), provided you concatenate the values into the hash as you go (re-using part of AnomalousMonk's code):
$ perl -wMstrict -MData::Dumper -e '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) { > $hash{$1} .= "$2;"; > } > print Dumper \%hash; > ' $VAR1 = { '1' => 'A;B;', '2' => 'G;H;V;' };