Not sure I really understand what you are looking for. My understanding is that your are looking for substrings like __(...) with various possible types of strings between the parentheses. I would suggest to use a regex to find these general patterns and then call a function to process (with further regexes) what's in between. It could look like this:
sub process {
print shift, "\n";
}
my $string = "ccc __(dddd)ccc __(eeee)ssss";
$string =~ s/__\(([^)]+)\)/process($_)/egis;
The advantage is to split the complex regex into two pieces, one applied to the larger text and then one for the template bits you have extracted. You could even call it recursively. Whether or not this makes sense or is faster, you would have to try.