in reply to Counting the number of replaces

If you want to get the number of replacements made in the whole file, not just for a particular line, then these should accumulate e.g. using += :
while( <$inputfh> ) { $replcount += s/replacethis/withthis/g; print $outputfh $_; }

-M

Free your mind