in reply to Calculations in Regexp

Here is one way:
use warnings; use strict; my $flag_count = 0; while (<DATA>) { $flag_count++ while /<BEGIN_FLAG>/g } print "flag_count = $flag_count\n"; __DATA__ <BEGIN_FLAG> foo bar goo <BEGIN_FLAG> boo <BEGIN_FLAG> __END__ flag_count = 3