my @sorted = map{$_->[0]} sort {$a->[1] <=> $b->[1]} map{ /chr(.+)/; my $x = $1; if ($x eq "X\r\n") {$x=23} if ($x eq "Y\r\n") {$x=24} $_=[$_,$x] } @unsorted;