use strict; use warnings; print map "sequence$_.gb.txt\n", sort { $a <=> $b } map { /(\d+)/; $1 } ; __DATA__ sequence3.gb.txt ....