in reply to variables in substition/eval

And if you have Perl version 5.10 or greater, here's a variation that uses the  \K variable-width positive look-behind operator:

c:\@Work\Perl\monks>perl -wMstrict -le "use 5.010; ;; my @lines = ( 'Once upon a time', 'scrooge & donald', 'went for a long walk', ); ;; my @list = qw(huey dewey louis); ;; foreach my $who (@list) { print qq{who '$who'}; foreach my $ln (@lines) { (my $newln = $ln) =~ s{ scrooge \s+ & \s+ \K donald }{$who}xmsg; print qq{ '$newln'}; } } " who 'huey' 'Once upon a time' 'scrooge & huey' 'went for a long walk' who 'dewey' 'Once upon a time' 'scrooge & dewey' 'went for a long walk' who 'louis' 'Once upon a time' 'scrooge & louis' 'went for a long walk'
See  \K in Extended Patterns section of perlre. (Could also use a standard look-ahead to achieve the original  scrooge (& donald) match.)


Give a man a fish:  <%-{-{-{-<