in reply to Ternary inside a regex

You're already using the /e modifier. Thus you can put into the replacement portion of the s/// operator "any" perl code. No reason why a ternary operator could not be there...