while (1) { if (-f $fn) { ## a file was found, do something DoSomething(); ## then exit exit; } ## pause 5 minutes before checking again sleep 300; }