I would suggest Regexp::Common:
use warnings; use strict; use Data::Dump; use Regexp::Common qw/balanced/; "(a a (a a)(a a))(b b(b)b b)" =~ /$RE{balanced}{-parens=>'()'}/; dd $&, $'; # ("(a a (a a)(a a))", "(b b(b)b b)")
Though of course there are plenty of other solutions, including Parse::RecDescent, though that might be a little overkill if this is all you're doing. See e.g. regex for nested "<"/">', and note that Text::Balanced is a core module.
In reply to Re: Matching nested parens
by haukex
in thread Matching nested parens
by BernieC
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |