in reply to Writing to flock files in a daemon

Check out Proc::PID_File.

use Proc::PID_File; die "Already running!\n" if hold_pid_file("/var/run/myproc.pid"); &do_something; exit; # pid file will be automatically removed here