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