sub by_my_criteria { return 1 unless length $a->[0]; return -1 unless length $b->[0]; return $a->[0] cmp $b->[0]; } sorted = map { $_->[1] } sort by_my_criteria map { [ $all{$_}->[$sortValue], $_ ] } keys %all;