in reply to Regex question

I note that you want to swap bmu but not amu. Given the conditional nature, you can use negative look-behind assertions to cause the match to fail if the matching string is preceded by an 'a':

$string2 =~ s/(?<!a)($greekReplace)/\\$1 /isg;

More info can be found in perlre and perlretut. If you want to encode abeta but not amu, you should swap your 'mu' entry in $greekReplace to (?<!a)mu.