in reply to counting matches in a line
my $count; while (<DATA>) { s/(this)/$count++;$1/ge; # non-destructive version } print "number of this = $count\n"; [download]