opendir(MYDIR, $dirname); while (condition) #condition ~ 1, loop basically forever { my @mail = grep { $_ ne '.' and $_ ne '..' } readdir INDIR; foreach (@mail) { # do stuff # delete each file } undef(@mail); # @mail shuld be empty now sleep(1); # give cpu a break } # more stuff... closedir(MYDIR);