my @s = map { $_->[1] } # get back the original value ($_ from the third step in the map) sort { $a->[0] <=> $b->[0] } # sort on $1 from below map { $c += 1; # count the regexs /(\d+)/; # put the digits from $_ into $1 [ $1, $_ ] # store $1, and $_ for later retrival } @l;