$ cat p5.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 "Orig----------\n"; print "|" . $stuff . "|\n"; print '$1------------' . "\n"; print "|" . $1 . "|\n"; print 'Match---------' . "\n"; print "|" . $& . "|\n"; print 'B4------------' . "\n"; print "|" . $` . "|\n"; print 'After---------' . "\n"; print "|" . $' . "|\n"; print "----------\n"; $ ./p5.pl Orig---------- |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.| $1------------ |(we go( in( and in (&stop)(awhile) ( further ))) but still (here) )| Match--------- |(we go( in( and in (&stop)(awhile) ( further ))) but still (here) )| B4------------ |On the outside now then | After--------- | and now (for a while) we are out again.| ---------- $