sub sorted_keys_by_value { my $hash = shift; return sort {$hash->{$a} cmp $hash->{$b}} keys %$hash; } @sorted_keys = sorted_keys_by_value(\%myHash);