$ cat p2.pl #!/opt/perl5.16/bin/perl use strict; use warnings; our $paren = qr/ # Need declared variable with use strict. \( ( [^()]+ # Not parens | (??{ our $paren }) # Another balanced group (not interpolated yet) )* \) /x; # 'x' means ignore whitespace, comments. 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 again."; $stuff =~ /($paren)/; print "----------\n"; print "$stuff\n"; print "----------\n"; print $1 . "\n"; print "----------\n";