my $path = "/path-to/some-dir"; opendir(DIR, $path) || die "Could not read $path - $!\n"; for my $fileFound (grep /^loyl\d+i_lgr\.sss$/, readdir(DIR)) { # do stuff here... } #### my $path = "/path-to/some-dir"; opendir(DIR, $path) || die "Could not read $path - $!\n"; while (my $fileFound = readdir(DIR)) { next unless $fileFound =~ /^loyl\d+i_lgr\.sss$/ # do stuff here... }