http://www.perlmonks.org?node_id=318381


in reply to = rather than =~ ?

Another potentially confusing variation would be if list context was used since the match will return the list of matched sub-expressions. In the example below, $input is assigned a value for each iteration wheras $1 is only changed on a good match.

#! /usr/bin/perl use strict; my $input; while (<DATA>) { ($input) = /(\w+)/; print "\$input=$input\t\$1=$1\n"; } __DATA__ Hello World

Output:

$input=Hello $1=Hello $input= $1=Hello $input=World $1=World