@TXT = map { s/\d+ //; $_ } sort map { s/(.*?)_(\d+)_/sprintf("%04d %s_%s_",$2,$1,$2)/e; $_ } glob( "*.txt" );