require "stat.pl"; ... for(;;) { open ML, " $st_size) { print "closing the file\n"; last; #file closed and new one started }else{ $old_ML_size = $st_size; } while (){ another_line(); } sleep 5; seek(ML, 0, 1); # reset end-of-file error } close(ML); }