you're not supposed to open, and then lock your lock/semaphore file, as in that gap of time, another copy of your program can open it also. any decent perl book (e.g. camel book) tells you how to get around it. Alternatively, read the docs and faqs on open and flock.