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.