my %hash = ( a=>0, b=>1, c=>0, d=>3 ); foreach my $k ( sort { $hash{$a} <=> $hash{$b} or $a cmp $b } keys %hash ) { print "$k = $hash{$k}\n"; } #### a = 0 c = 0 b = 1 d = 3