use List::Util qw( max ); my %h = (a=>2, b=>8, c=>7); my $max = max values %h; my %key_for_val = reverse %h; %h = ( $key_for_val{$max} => $max );