in reply to Code Sub-Pattern Error "Panic: top_env"

FYI on Posting at Perlmonks in-a-nutshell; put your paragraphs inside <p></p> tags, and your code inside <code></code>. In your browser, select "view source" on this page and look at this post. It should show you (kind of...) the extra tags and their placement, which you can compare with what this post actually looks like. Also, you can preview your post as many times as you like until it looks right

As you said yourself, the code you've written may be stupidly over-complicated... but I'm assuming you're posting here not because of the code itself, but because the code produces an apparent bug with the Perl interpreter...

I found the debug switch use re qw{eval Debug ALL};, gives the extra output below:

Compiling REx "(?(?{$_ =~ |$regex (\w+ \w+)(?=\1)|})(?{s|$1||})|(?{s|$ +1 \w+"... Starting first pass (sizing) >(?(?{$_ =~... | 1| reg | | brnc | | piec | | atom >?(?{$_ =~ ... | | reg >?{$_ =~ |$... | 2| reg >(?{s|$1||}... | 6| brnc | | piec | | atom >?{s|$1||})... | | reg >(?{s|$1 \w... | 12| brnc | | piec | | atom >?{s|$1 \w+... | | reg Required size 16 nodes Starting second pass (creation) >(?(?{$_ =~... | 1| reg | | brnc | | piec | | atom >?(?{$_ =~ ... | | reg >?{$_ =~ |$... | 2| reg panic: top_env C:\Temp\panic>
And this is where i get stuck on where to go next with the investigation... perhaps another monk could shed further light?

As you've noted from perldiag, a panic usually indicates a bug...
Next steps would be to distill the REx down to the most simple form that produces the issue. Then checkout if its a known fault... (can another more enlightened monk comment on where and how faults with Perl can be queried?)