in reply to Matching patterns containing a caret

Escape it by placing a \ before the caret.
$p = $s = "\^xxx"; print "$p has $s\n" if $s =~ /$p/; #does not print

Replies are listed 'Best First'.
Re^2: Matching patterns containing a caret
by almut (Canon) on Apr 26, 2009 at 10:15 UTC
    $p = $s = "\^xxx";

    You probably meant

    $s = "^xxx"; $p = '\^xxx'; # or "\\^xxx" ...

    (a backslash in a double-quoted string just escapes the next char...)

      Why worry about quoting constructs? qr// has worked very well for ages:

      my $p = qr/\^xxx/;