for (map $_->[1] => sort {$a->[0] <=> $b->[0]} map {m/fwlogsum\.(\d+)\w+/; [$1, $_]} @files ){ print "fwlog" . $_ . ".Mar2005\n"; }