$rxNest = qr{(?x) \( (?: (?>[^()]+) | (??{$rxNest}) )* \) }; $string =~ /$rxNest/; #### $rxNest = qr{ \( (?: (?>[^()]+) | (??{$rxNest}) )* \) }x; #### (?{ local @memoList = (@memoList, $+) }) #### (?{ local $offset = $offset + 1; local $memoList[$offset] = $+ }) #### $string =~ /^$rxNest\z/;