my %hash = (f => 'd', c => 'a', b => 'e'); my @keys_ordered_by_value = sort { $hash{$a} cmp $hash{$b} } keys %hash; # ^^^ # \|/ # to sort numeric values use <=> here -------+ # to sort in reverse order swap $a and $b: { $hash{$a} cmp $hash{$b} } foreach my $key (@keys_ordered_by_value) { print "key = $key, value = $hash{$key}\n"; }