BEGIN { our $LOCKFILE = "/tmp/frogs.pid"; die "Another process is already running (see content of $LOCKFILE for pid)...\n" if -e $LOCKFILE; open my $out, '>', $LOCKFILE or die "cannot open $LOCKFILE - $!"; print $out "$$\n"; close $out; # chmod 0600 ... if you like } warn "running... with PID: $$ ...\n"; sleep 10; END { unlink $LOCKFILE or die "cannot remove lock-file $LOCKFILE - $!"; }