my %hash; while (my ($k,$v) = each %values) { push @{$hash{$v}}, $k; }