my %hash_inverted; for (keys %hash) { my $value = $hash{$_}; push @{ $hash_inverted{$value} }, $_; }