#! perl use strict; use warnings; my %h1 = ( 'Chicago, USA' => undef, 'Frankfurt, Germany' => undef, 'Berlin, Germany' => undef, 'Washington, USA' => undef, 'Helsinki, Finland' => undef, 'New York, USA' => undef, ); my %h2; for (keys %h1) { my ($city, $country) = split ', '; push @{ $h2{$country} }, $city; } for (sort keys %h2) { print "$_: ", join(', ', sort { $a cmp $b } @{ $h2{$_} }), "\n"; } #### 16:29 >perl 819_SoPW.pl Finland: Helsinki Germany: Berlin, Frankfurt USA: Chicago, New York, Washington 16:31 >