#!/usr/bin/perl use strict; use warnings; use Fcntl qw(:DEFAULT :flock); my $sec = 30; print 'Please type the file that I should lock for $sec: '; my $file = ; chomp $file; sysopen( FH, $file, O_RDWR ) or die "Cannot edit $file: $!\n"; flock( FH, LOCK_EX ) or die "Cannot lock $file: $!\n"; print 'Ok, holding the file for $sec seconds. I will not change anythingin the file', "\n"; sleep $sec; close(FH); print "Finished\n";