use warnings; use strict; use feature 'say'; use File::Replace 'replace3'; my ($file, $pat, $replace) = @ARGV; my $Count = 0; my ($infh, $outfh, $rep) = replace3($file); while (<$infh>) { chomp; if ( s/$pat/$replace/g ) { $Count++ } say {$outfh} $_; } $rep->finish; say "Count=$Count"; #### perl -wMstrict -i -nle 's/PAT/REPL/g and $a++;print}{print $a//0' FILE