use Benchmark; $start = new Benchmark; open(FH, "wrongs") or die $!; open(FH2, ">wrongs2") or die $!; while ($line = ) { $counted = () = $line =~ s/wrongs/wrongs4/; $counted2++ if $counted; print FH2 "$line"; } close (FH); close (FH2); $end = new Benchmark; # calculate difference $diff = timediff($end, $start); print "replaced: $counted2 The operation took: " , timestr($diff, 'all'); # output # replaced: 35000 The operation took: 0 wallclock secs ( 0.23 usr 0.03 sys + 0.00 cusr 0.00 csys = 0.27 CPU)