in reply to Find and Replace

Since you are already treating your file like an array of lines, you might be interested in Tie::File.

Also, your code has major problems: use strict and warnings. Compiling your code generates warnings:

perl -wc -Mdiagnostics 830674.pl
This generates errors:
perl -wc -Mdiagnostics -Mstrict 830674.pl