$stop = 0; while ($stop == 0) { if (-e "the.lock") { sleep(1); } else { open (FIL,">the.lock"); close FIL; } more code unlink("the.lock"); $stop = 1;