Used black magic to count matches

It turns out perl has a wealth of operators for finding matches in a string.
I was going to implement KMP, but this was much easier. I need to figure out
exactly what ?= does.