As Tanktalus says, this is almost certainly caused by recursion going past the end of the available stack space. I expect that it is caused specifically by the very first fragment of your regexp:
(?:.*\n)*?
.. the first time you try to use it on a file that has a few thousand lines not matching the next part of the pattern.
Since that fragment has no effect other than to ensure the rest of the pattern is anchored to the start of the line, I would suggest replacing:
m/(?:.*\n)*?rest of pattern/
with:
m/^rest of pattern/m
which I believe will solve your problem.
Hugo