use File::Flock; # the following croaks if it fails my $lock = new File::Flock("C:\lock_file"); # do whatever here # this will happen automatically once $lock # goes out of scope but it doesn't hurt to do # it explicitly once you're done with the lock $lock->unlock();