in reply to Looking for alternative syntax for assigning variables based on regex matches
OUTPUT:perl -wle '$foo = "a hello w"; $foo = $foo =~ s/(?=.*(hello)).*/$1/sr; + print $foo'
And if you want only to use your capture, just:hello
In the later example a value of $foo didn't change....; print $foo =~ s/(?=.*(hello)).*/$1/sr;
Though it looks like bad practice to change a variable while it is in use....; $foo =~ /hello(?{ $foo = $& })/; print $foo
|
|---|