http://qs1969.pair.com?node_id=11129009


in reply to Looking for alternative syntax for assigning variables based on regex matches

With non-destructive /r modifier (and lookahead):
perl -wle '$foo = "a hello w"; $foo = $foo =~ s/(?=.*(hello)).*/$1/sr; + print $foo'
OUTPUT:
hello
And if you want only to use your capture, just:
...; print $foo =~ s/(?=.*(hello)).*/$1/sr;
In the later example a value of $foo didn't change.
*Updated

+one more way:
...; $foo =~ /hello(?{ $foo = $& })/; print $foo
Though it looks like bad practice to change a variable while it is in use.