Jeremy Kister wrote: > > perldoc -q quote talks about \Q before a regex to escape special > characters. > > how do you use \Q when you want to anchor the regex with a dollar sign ? > > my $string = my $regex = "foo"; > print "match\n" if($string =~ /^\Q${regex}$/);
\E marks the end of the string you want escaping (without it all non-word characters are escaped up to the end of the regex) so you can write: print "match\n" if($string =~ /^\Q${regex}\E$/); By the way you can miss out the curly brackets around the the scalar identifier here as it's unambiguous: print "match\n" if($string =~ /^\Q$regex\E$/); but that isn't necessarily the case - it depends upon what appears after the scalar in the regex. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>