s{ ( [(] [^()]* [)] ) # Leave text in parens alone | <(\w+)> # Replace with $replace{word} }{ $1 ? $1 : $replace($2) }gex;