Perl search and replace file content.

I am not sure if this is doable. I am trying to open and print the content of the file by replacing all instances fo perl to PERL . This is my code but it is
giving me the number count instead of the actual lines with changes.

open (PERLHISTORY, 'sample.txt') or die "The file sample.txt could not be found\n";

@B = <PERLHISTORY>; #Reads the whole line

while ($Line = shift(@B))
{
$NewLine = ($Line =~ s/perl/PERL/gi);
print $NewLine; # This gives a count not the actual changed line
}

undef $/;
open $fh,"<","a.txt" || die "Can not open file";
my $str=<$fh>;
$str=~s/perl/PERL/ig;
print $str;
perl -ne 's/perl/PERL/g;print' file

Thanks Cherry. That worked well. I am not yet familiar with the concept of
undef, but I will get there.