in reply to RegEx to find the index of the character '@' in an Email address

Regular expressions are not strings, so don't use $mail =~ "...";. Maybe you want to just use index instead of a regular expression?

If you really want to use a regular expression, don't use strings, use regular expressions:

... if( $mail =~ /\@/ ) { ... } ...

Replies are listed 'Best First'.
Re^2: RegEx to find the index of the character '@' in an Email address
by JavaFan (Canon) on Jul 26, 2010 at 16:02 UTC
    Regular expressions are not strings
    Right, but numbers aren't strings either.

    Remember, this is Perl. If you use a string as a regexp, Perl will treat it as a regexp.

    my ($local_part) = $mail =~ '^([^@]*)';
    works just fine.

      Sure, but if you use double quoted strings, you forego the convenience of Perl knowing that you mean to write a single backslash when you want a backslash to appear in the regular expression.