my @unsorted = ; my @sorted = sort { ($a=~/chr([A-Z])/)[0] cmp ($b=~/chr([A-Z])/)[0] || ($a=~/chr(\d+)/)[0] <=> ($b=~/chr(\d+)/)[0] } @unsorted;