foreach (reverse sort {$hash{$a} <=> $hash{$b} || $a cmp $b} (keys %hash)) #### 1 2 3 4 5 6 7 8 9 10 11 #### 1 7 2 8 3 9 4 10 5 11 6