in reply to Regex code block executes twice per match using look-arounds

A alternate solution, just for fun.

use strict; use warnings; my $paren_grp_re = qr/ \( [^ ) ]* \) /x; my $square_grp_re = qr/ \[ [^ \] ]* \] /x; my $curly_grp_re = qr/ { [^ } ]* } /x; my $angle_grp_re = qr/ < [^ > ]* > /x; my $string = '<x1>[x2]{x3}(x4)'; print "Before: $string\n"; $string = join '+', map / $paren_grp_re | $square_grp_re | $curly_grp_re | $angle_grp_re | [^\(\[\{\<] /xg, $string; print "After: $string\n";

Doesn't support nesting.