Example 1: A(B(2)) Example 2: A(B(2)+C(D())) #### #!/usr/bin/perl -wT # example 1 my $text = "A(B(2))"; $text = doFunc( "MAIN", $text ); print "Example 1: $text\n"; # example 2 $text = "A(B(2)+C(D()))"; $text = doFunc( "MAIN", $text ); # this fails! print "Example 2: $text\n"; sub doFunc { my( $theFunc, $theParam ) = @_; # FIXME: greedy match fails with: 'TT(TT()+TT(TT()))' $theParam =~ s/([A-Z]+)\((.*)\)/&doFunc($1,$2)/geo; my $result = ""; if( $theFunc eq "MAIN" ) { $result = $theParam; } else { # dummy switch here for demonstration # this would be an elsif for each function $result = "func $theFunc returns <$theParam>"; } return $result; }