in reply to Applying a regular expression to a string

=~ is not related to the ~ operator; the assignment variant of ~ would be ~=, except that ~ is a unary operator and so has no assignment variant.

What you want is to select everything before the first \s, and assign that to $message_id; use a match, not a substitution, to do that:

($message_id) = $message =~ /^(\S*)/;
(Note the parentheses around $message_id that make it a list assignment; you need to do the assignmentmatch in list context to have it return anything besides success/failure.)

Replies are listed 'Best First'.
Re^2: Applying a regular expression to a string
by mw (Sexton) on Apr 07, 2005 at 07:50 UTC
    Simple and elegant. I will start using this construct as soon as I next come across this type of problem. Thank you all.