m{ A (?: [^AB]+ | .B )* [^AB]* A }x; [download]
In reply to Re: Perl's regex engine causes me distress by japhy in thread Perl's regex engine causes me distress by japhy