$batch_dir = "batch/"; $log_dir = "batchlog/"; while (1) { opendir( D, $batch_dir ) or die; print "checking $batch_dir for files\n"; @batchfiles = grep { !/^\./ } readdir(D); unless (@batchfiles) { print "Done: no more files to process\n"; exit; } # batchfiles contains all files at # most recent readdir() foreach $file (@batchfiles) { open( F, "$batch_dir$file" ) or die "$!"; while () { do_stuff_with($_); # actual processing omitted } close(F); rename("$batch_dir$file","$log_dir$file") || die "$!"; print "finished $file\n"; } }