First, watch out for the 'dot' in your set, which Perl interprets as "stuff" (i.e. not a linefeed ('\n'), unless you're using crazy regexp options like /s). You probably mean literal-dot ('\.') instead.

Secondly, I'm not sure why you're using a negative match assertion ('!~') instead of a positive one ('=~'). It seems to be the opposite of what you're looking for:      if ($entry =~ /^([a-zA-Z0-9\@_\.]*)$/) { This code memorizes the entire e-mail address, which is apparently what you intended by using the brackets in your regexp. As a note, though, since you are memorizing the entire thing, why bother to do this instead of just using $entry?

Note: On the subject of e-mail address matching regexps, you will have to be more open-minded about what can appear in these. For example, many characters other than the ones you specified are actually valid in the e-mail address part of the name. I would modify it so that the checks on the e-mail address part are more liberal, and further, that instead of using the star operator (0 or more), which has the unfortunate effect of validating a zero-length string(!), that I would demand at least one character on each side.     if ($entry =~ /^([a-zA-Z0-9_\.\-\!\%\#]+\@[a-zA-Z0-9_\.]+)$/) { Here's some e-mail addresses which could be used to test any modifications:
qw [ abc@123.it a@b tech-support@super.net user_144@z.com webmaster@estherdyson.museum ];
Tip: It is probably a good practice to "escape" all non-alphanumeric characters in your regexps until you know which ones are safe. As you found out, a seemingly inert '@' was interpreted otherwise, and the unassuming '.' means a whole lot more than just dot inside a regexp.

In reply to Re: @ in regex, or not? by tadman
in thread @ in regex, or not? by JPaul

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.