in reply to Reading directories and parsing standard names

No need to sort if you just want the highest number:
my ($max_file, $max_num); while (defined(my $file = <foo_*.bar>)) { ($max_file, $max_num) = ($1, $2) if $file =~ /^(foo_(\d+)\.bar)$/ and (!defined $max_num or $2 > $max_num); } print "$max_file\n";