use strict; use Fcntl qw(:DEFAULT); my $semaphore = 'c:/test.txt'; sysopen (SEMAPHORE, $semaphore, O_WRONLY | O_EXCL | O_CREAT) or &busy; print "There can be only one!"; sleep 20; close SEMAPHORE; unlink $semaphore or die "Can't unlink $semaphore $!\n"; exit; sub busy { print "Sorry, I am busy!"; exit; }