my %revhash; while (my ($key, $value) = each %hash) { push @{$revhash{$value}}, $key; } for (sort keys %revhash) { print "$_ => @{$revhash{$_}}\n"; }