Do you want to make sure that the string does not contain .com.com or do you want to make sure that the string does not contain .com twice? See index and rindex:
for my $mail (qw( bar@foo.com.com
bar@foo.computers.com
bar@com.computers.com
bar@b.com.computers.org)) {
print "Looking at '$mail'\n";
printf "index '.com': %d\n", index '.com', $mail;
printf "index '.com.com': %d\n", index '.com.com', $mail;
printf "rindex '.com': %d\n", rindex '.com', $mail;
}
You could also create a regular expression that has a lookahead component, but as your problem is not well-defined, I won't write it. |