sub my_sort_key { my $file = lc(shift); chomp $file; my $the_file =~ s/^the\s+//; $the_file; } my @files = map { $$_[1] } sort { $$a[0] cmp $$b[0] } map { [ my_sort_key($_), $_ ] } ;