in reply to Re^6: Poorly written script
in thread Poorly written script

Check for the files the same way you do now, just do it in the loop. Maybe something like:

while ($filehandle = get_next_file()) { ... }

So you spin off your "check if the file exists" and "open the file" code into a new function, and keep doing the loop while there are more files to find.