in reply to a regular expression problem

In the general case, to execute some code (e.g. count) every time a pattern is found, you could use a while loop with m//g:

$_ ='abacdbccdeeabacdbccdee'; my $cnt; while (/[bc]/g) { last if ++$cnt == 3; } say pos;