in reply to Search and add lines into a file. Getting bareword error.

The line

print FH

does not make sense. Did you mean

print FH $_;

UPDATE: A pair of {} is missing after the "if" line as well. print FH $; does not make sense either.

Can you make the script work in your sense, and re-post to make sure I can look at the right one? It is a bit difficult to guess what the issue is...

CORRECTION: It seems to create your desired output now...