while (1<2) { opendir (DIR, $dir) or die "cannot opendir $dir"; my @only_files = grep {-f "$dir/$_"} readdir(DIR); readdir DIR; closedir DIR; foreach $file (@only_files) { &process_file ($file); } sleep(10); }