You shouldn’t need to reach for Perl, you can use the parity directly in the regular expression, no? Getting escaping right will depend on the context in which the regex is used (might need to double-\) but a global replace of \$\$?(.*?)\$\$? with \($1\) might be a start?