good idea, but this won't work because there may be multiple pairs of outermost (i.e., same level) brackets. so, a greedy regular expression will grab beyond. i should have clarified this. for example:
$str = '
blah blah blah blah
blah
blah blah blah [blah
[blah blah] [blah blah blah
blah] blah]
blah blah
blah blah blah blah
blah
blah blah blah [blah
[blah blah] [blah blah blah
blah] blah]
blah blah
blah blah blah blah
blah
blah blah blah [blah
[blah blah] [blah blah blah
blah] blah]
blah blah
blah blah blah blah
blah
blah blah blah [blah
[blah blah] [blah blah blah
blah] blah]
blah blah';
in other words, there are multiple top-level bracket pairs, which, may or may not, contain additional pairs (etc).
btw, here is the code snippet that i finally used (which has some nuances that i didn't include in the original question), based on the previous suggestion:
my $re = qr{\[(?:(?>[^\[\]]+)|(??{$re}))*\]}s;
for (;;) {
last unless $tempstr =~ s/(\[\w+?\s*=\s*($re|\n|[^\[\]
+])+\])/&assign($1)/gies;
}
|