http://qs321.pair.com?node_id=1218448


in reply to Regex for outside of brackets

I think this may be close to what you are asking, and only uses a module shipped in core, Text::Balanced:

$ perl -MData::Dumper -MText::Balanced -le ' use 5.010; $Data::Dumper::Deepcopy = $Data::Dumper::Sortkeys = 1; my $c = q{This is outside (This is inside).}; my %found; ( $found{prefix}, $found{bracketed}, $found{postfix}, ) = Text::Balanced::extract_multiple($c, [ \&Text::Balanced::extract_bracketed, ], ); say Data::Dumper->Dump( [ \%found, ], [ qw( *f ) ] ); ' %f = ( 'bracketed' => '(This is inside)', 'postfix' => '.', 'prefix' => 'This is outside ' );

Hope that helps.