my @numbers = map /object(\d+)000/, grep -d, readdir(DIR); #### use List::Util 'max'; my $highest = max map /object(\d+)000/, grep -d, readdir(DIR); #### my $highest = max map /object(\d+)000/, grep -d, glob 'object???000';