my @sorted_keys = sort { extract( $hash{ $a } ) <=> extract( $hash{ $b } ) } keys %hash; for my $key ( @sorted_keys ) { # whatever }