in reply to find & replace a string in perl

You have numerous errors here. Add use strict; and use warnings; to the top of your code. Run it again and see if you can figure out some of the problems.

Your description in not very clear. Without seeing sample input, I'm not sure if you want to change test to #test or Some line with test in it to #Some line with test in it - take a look at perlre.

Use the three-argument form of open and let Perl tell you why it can't open the file (i.e. or die $!) - your current output of "file could not open" will be of no help to you at all.

If you're still stuck after that, post your updated code with a sample of input data and whatever output your code produces.

-- Ken