#!/usr/bin/env perl use strict; use warnings; use Fcntl qw(:flock); my $highlander; BEGIN { open $highlander, '<', $0 or die "Couldn't open $0: $!\n"; flock $highlander, LOCK_EX | LOCK_NB or do { warn "There can only be one $0\n"; exit; }; } # Other use statements... # code...