foreach my $key (keys %hash) { $newhash{$hash{$key}} += $key; }