in reply to Substituting a comma only when it is preceded and followed by a bracket

Untested:
my $str = do {my $i; join "", map {$_ eq '(' ? $i++ : $_ eq ')' && $i +? $i-- : $_ eq ',' && $i ? ($_ = ';') : 0; $_} split '[(,)]', $str};
This assumes the parenthesis are balanced.

But what should happen on:

"(foo),(bar)"
? The comma here is preceded and followed by a bracket - preceded by an opening paren, and followed by a closing paren even. If such a comma should be replaced as well, one might use something like (untested):
substr($str, index($str, "("), rindex($str, ")") - length($str)) =~ s/ +,/;/g;