use strict; # example 2 my $text = doFunc( "MAIN", "A(B(2)+C(D()))" ); print "Example 2: $text\n"; sub doFunc { my( $theFunc, $theParam ,$re) = @_; {no warnings "uninitialized"; ($re=$theParam)=~s/((\()|(\))|.)/${[')']}[!$3]\Q$1\E${['(']}[!$2]/gs; } $re= join'|',map{quotemeta}eval{$theParam=~/$re/}; die $@ if $@=~/unmatched/; #$re = qr/$re/; print "$theFunc: '$theParam' =~ /$re/\n"; print join"\n",$theParam=~/([A-Z]+)\(($re)\)/g,"\n"; $theParam =~ s/([A-Z]+)\(($re)\)/&doFunc($1,$2)/ge; return "func $theFunc returns <$theParam>"; } #returns #Example 2: func MAIN returns +C(D())>> #should return #Example 2: func MAIN returns +func C ret\urns >>> #