Besides the good advice you've received above, you should also investigate regex anchors ^ and $, for example:
s/^$file$/something goes here/
Search for "anchor" in perlretut#Simple word matching.
Quantum Mechanics: The dreams stuff is made of
|Replies are listed 'Best First'.|
Re^2: How to handle metacharacters in input file for Perl one-liner code
by debug (Initiate) on Jul 17, 2015 at 06:42 UTC