Gummo, '\' is a literal in between \Q and \E. '\Q\E\E' matches '\' with the second '\E' being superfluous. the rule is simpler than you make it out to be: '\Q' quotes a string up until the very next occurrence of '\E'. everything single thing in between '\Q' and '\E' is treated literally - that is why the simplest way to escape '\E' in the middle of a quote is to use '\E\E\Q', and that is why replacing every occurrence in that way results in a correctly quoted string 100% of the time.