sub kv_for_largest_v { my $hr = shift; return undef unless keys %$hr; my ($k,$v) = each %$hr; my @rv = ([ $k, $v ]); while (my ($k2,$v2) = each %$hr) { if ($v2 > $rv->[0][1]) { # New maximum value, reset the list $rv = ([ $k2, $v2 ]); } elsif ($v2 == $rv->[0][1]) { # Another copy of the max distance, add to the list push @rv, [ $k2, $v2 ]; } } return \@rv; }