foreach ( sort { $hash{$a} cmp $hash{$b} || $a cmp $b } keys %hash ){