#/usr/bin/perl use warnings; use strict; my %hash = (a => 4, b => 6, c => 2); my @sorted_keys = sort keys %hash; print "@sorted_keys\n"; my @sort_by_value = sort{my $A = $hash{$a}; my $B = $hash{$b}; $A <=> $B ## or cmp for strings }keys %hash; print "@sort_by_value\n"; __END__ Prints: a b c # simple key sort c a b # keys sorted by value of keys