use strict; print &openit; sub openit { eval "use Fcntl qw(O_CREAT O_EXCL O_WRONLY);"; die $@ if ($@); my $fp = "c:\\temp\\test.csv.lck.tmp"; die "Unable to open $fp" if !sysopen (my $fh, $fp, O_WRONLY() | O_CREAT() | O_EXCL()); close $fh; unlink $fp; return $fp; }