my @inkeys = map { # extract the original key name from the sorted # array refs, and return them in a list to @inkeys $_->[2]; } # sort the array refs: first sort alphabetically # (cmp) on the first element, then numerically # (<=>) on the second element sort { $a->[0] cmp $b->[0] || $a->[1] <=> $b->[1] } # 'map' passes a list of array refs to 'sort' map { # split the key name into alpha and numeric parts my ( $alf, $num ) = $_ =~ m/([a-z]+)(\d+)/i; # create an array ref with the two parts of the # key that will be used for sorting, and the # original key name, return the array ref [ $alf, $num, $_ ]; } keys %{ $href };