Not sure if this is what you're looking for, but quotemeta will return its argument string with all metacharacters quoted (preceded by backslashes, in case that's relevant). Take a look at perlfunc.
HTH
Comment on Re: Problems with matching and metacharacters