in reply to deleting a line from a text file

The loop over the %FORM hash keys is really confusing. I think you don't need it. From your description you want to check the lines from the input file against the hash keys, but you never do that. I think you need something like that (not tested):
open OLD, $file or die "Can't open $file:$!\n"; open NEW, ">$file.new" or die "Can't open temp file $file.new: + $!\n"; my $found =0; while (<OLD>) { if ($FORM{$_}==1) { $found =1; next; } print NEW; } } close NEW; close OLD; if ($found) { rename ("$file.new", $file) or die "Can't rename new $file: $ +!\n"; } else { print "I didn't find !\n"; }
What I changed:

You could look at File::Atomic if you run this concurrently.