in reply to search for matching parentheses

use strict; use warnings; use Regexp::Common qw(balanced); my $input = q|Param1(info, blah), Param2(new info(DN), blah), camel Param3(), LLama, Param4 (stuff)|; my $PATTERN = $RE{balanced}{-parens=>'()'}; my @pieces = (); INPUT: while (length $input) { $input =~ s{\A [^\w\(]+ }{}x; ## skip leading junk if ($input =~ s{ (\w* $PATTERN) }{}x ) { push @pieces, $1; next INPUT; } last INPUT; } printf "%s\n", join qq(\n), @pieces;
prints
Param1(info, blah) Param2(new info(DN), blah) Param3() (stuff)
cheers