I have a CGI script which takes two strings. It searches for the first string in a file, replacing it with the second one. This file isn't really important, more for fun, so I'm not too worried about people deleting the whole file if they actually type out the contents as the first string. However, I would like for things like . and \w to search for those string literals, rather than for any character or any word character, respectively. Is there some function or capability which escapes all special characters in a string before it is passed to a regular expression?