open(OLD, "< $old") or die "can't open $old: $!"; open(NEW, "> $new") or die "can't open $new: $!"; flock (OLD, 2); flock (NEW, 2); [continue as before including renaming the file before the filehandles are closed]