#! perl -sw use strict; # Without the next %table referes to a global var which doesn't declaration. my %table; while (<>) { chomp; my ($city, $country) = split /, /; push @{$table{$country}}, $city; # The line above is equivalent to =pod if (not exists $title{$country}) { my @array; push @array, $city; $title{$country} = \@array; } else { my $arrayRef = $title{$country}; push @{$arrayRef}, $city; } =cut } foreach my $country (sort keys %table) { print "$country: "; my @cities = @{$table{$country}}; print join ',', sort @cities; print ".\n"; #The 3 lines above could be replaced by =pod print join( ',' @{$table{$country}} ), "\n"; =cut }