use strict; use warnings; sub lock(*$){ flock($_[0],$_[1]); } my $file="foo"; my $text="hallo"; open(FH, ">$file") or die $!; lock (FH,2); print FH $text; lock FH, 8; close(FH);