#!/usr/bin/perl -w use Benchmark; timethese(100, { a => q{ my %hash = (key1 => 3, key2 => 2, key3 => "test"); # I used 10000 more for a large test set (omitted for brevity) @keys = sort { $hash{$b} cmp $hash{$a} || length($b) cmp length($a) || $b <=> $a } keys %hash }, b => q{ my %hash = (key1 => 3, key2 => 2, key3 => "test"); # I used the same 10000 more as above @keys = map { $_->[0] } sort { $b->[1] cmp $a->[1] || $b->[2] <=> $a->[2] || $b->[0] cmp $a->[0] } map{ [$_, $hash{$_}, length $_] } keys %hash; } }); #### Benchmark: timing 100 iterations of a, b... a: 274 wallclock secs (272.26 usr + 0.22 sys = 272.48 CPU) b: 366 wallclock secs (359.06 usr + 0.52 sys = 359.58 CPU)