His example, slightly modified for Perl:<p><pre><code> my $emailPattern = qr{ ^ #begin of line
([a-z0-9_.-]+) #one or more letters, numbers, _ . or -
@ #followed by an @ sign
([\da-z.-]+) #then one or more letters, numbers, _ . or -
\. #followed by a period
([a-z.]{2,6}) #followed by 2 to 6 letters or periods
$ }xi; #end of line and ignore case
if( 'john.smith@gmail.com' =~ $emailPattern ){
print "E-mail is valid\n";
} else {
print "E-mail is invalid\n";
}
</code></pre>
EDIT: A much better way of doing it though:<p><pre><code> use Mail::Sendmail;
if( 'john.smith@gmail.com' =~ /$Mail::Sendmail::address_rx/ ){
print "E-mail is valid\n";
} else {
print "E-mail is invalid\n";
}</code></pre>