The character "|" is special in a regular expression. It has to be escaped with a backslash to match itself. Unfortunately, the backslash is a special character in a string. It must be escaped with another backslash to put into the string. So the required string is:

Although your method "works", I would still recommend qr for regular expressions becuse you do not have to be concerned about a mixture of string and re syntax. Note: you can get the advantage of the quotemeta by using the equivalent re syntax \Q.