shows how to use regex's to isolate parenthesised text within a string with handling of nested/multiple parentheses. Cozens constructs a recursive Regex, and uses the ( ??{ $regex_variable } ) construct to defer interpolation of the variable until execution. It works for me!:

$ ./p2.pl
----------
On the outside now then (we go( in( and in (&stop)(awhile) ( further )+)) but still (here) ) and now (for a while) we are out again.
----------
(we go( in( and in (&stop)(awhile) ( further ))) but still (here) )
----------
$

But if I try to use the regex again it does not work as I think it ought. In the above code when I replace the matching regex with /($paren)^()*($paren)/ I expect $2 to be "(for a while)", but that does not work:

I did not really understand what your problem is, and it is a bit late for me now, so I have to give up trying to get the point. Just one point that I noticed, though, and may possibly explain unexpected behavior: the $stuff variable is not the same in the two programs:

my $stuff = "On the outside now then (we go( in( and in (&stop)(awhile+) ( further ))) but still (here) ) and now (for a while) we are out a+gain.";
my $stuff = "On the outside now then (we go( in( and in(&stop)(awhile)+ ( further ))) but still (here) ) and now (for a while) we are out ag+ain.";

Or to show it more clearly (I hate the way the Perlmonks site dispays code snippet, why should it cut it at line 70 or 71, making any significant code almost unreadable, at a time where most people don't have any problem displaying 250 or 300 characters on their screen?), I"ll just quote where the difference is:

Or, to put it in a somewhat more user-friendly manner, click on the "user settings" link in the comment to which I am replying, and you will be taken to a long list of configuration options, none of which have anything to do with line-wrap or code-wrap. However, at the top of that page are links for ten or so *more* pages of settings that you can mess with. Fortunately the very first of these, "Display Settings", has the needed stuff. Within the several tables of configuration options are selections to turn off code wrap altogether, or increase the length before wrap happens. I turned off wrapping, it works for me.

I must've done that after I copied one program to the other, but it does not matter, in both programs that area is inside the first pair of parenthesis, and it gets included in the match.

Anonymous Monk:
"I think you have one too many $parens..."

I do not know how to say what the problem is any differently. I *want* to use $paren a second time and have it find the *second* separate parenthesized text string within the $stuff variable, and set the $2 regex memory variable equal to it. The regex defined in the variable $paren is set works, it successfully finds the first open '(' and balancing close ')' pair of parenthesis. Because I use it as:

The sample $stuff variable does have a second, separate parenthesized text string in it ( "(for a while)" ) how come the same $paren regex does not find that second parenthsized string and set $2 to it?