Actually, in this particular case, it should work with and without quoting, because /@@/ doesn't interpolate anything (as opposed to /@@x/ or /\Q@@x\E/, for example).

#!/usr/bin/perl use warnings; use strict; $_ = 'foo@@bar'; print "matched\n" if /@@/; print "matched\n" if /\Q@@\E/; print "matched\n" if /\@\@/; __END__ matched matched matched

Update: maybe a better (anchored) check, avoiding the potential gotcha of matching against a single-@ pattern:

#!/usr/bin/perl use warnings; $_ = '@@'; print "1 matched\n" if /^@@\z/; print "2 matched\n" if /^\Q@@\E\z/; print "3 matched\n" if /^\@\@\z/; print "4 matched\n" if /^\Q@@x\E\z/; # doesn't match, because @x is be +ing interpolated print "5 matched\n" if /^@\@x\z/; # doesn't match, because there is + no 'x' in the string __END__ Possible unintended interpolation of @x in string at ./811585.pl line +10. Name "main::x" used only once: possible typo at ./811585.pl line 10. 1 matched 2 matched 3 matched

In reply to Re^2: regular expression with @@/ by almut
in thread regular expression with @@/ by jim_neophyte

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.