for (@files){ $_ =~ /fwlogsum\.(\d+)\w+/; push (@days, $1); } for (sort{$a <=> $b} @days){ print "fwlog" . $_ . ".Mar2005\n"; }