http://www.perlmonks.org?node_id=16794


in reply to How do I split a string on highly structured/nested data?

One approach is to use a parser like Parse::RecDescent. A real parser (as opposed to parsing a string with a regular expression alone) is much more powerful and can be more apropriate for parsing highly structured/nested data like your example.
use Parse::RecDescent; my $teststr="a,b,op2(c,d),op3(e,op4(f,g))"; my $grammar = q { content: /[^\)\(\,]+/ function: content '(' list ')' value: content item: function | value list: item ',' list | item startrule: list }; my $parser = new Parse::RecDescent ($grammar) or die "Bad grammar!\n"; defined $parser->startrule($teststr) or print "Bad text!\n";
For other approaches see the discussion on Balancing Parens.