http://www.perlmonks.org?node_id=413224


in reply to Re: Count multiple pattern matches
in thread Count multiple pattern matches

This won't work correctly if keywords overlap.

For example, consider the string foops. This actually matches both foo and oops. But if you remove foo in the first iteration, the remaining string (ps) won't match the keyword oops, thus reducing the match count for oops from 1 (the correct result) to 0.