You’re right, I didn’t take newlines into account. You could always chomp the line before the substitution. However, to do it all in one step, you need to add an /s modifier to the (regex part of the) substitution:
12:51 >perl -wE "my $s = qq[Hello world. \n]; $s =~ s/^.*(world).*$/m +onks/; say qq[|$s|];" |monks | 12:51 >perl -wE "my $s = qq[Hello world. \n]; $s =~ s/^.*(world).*$/m +onks/s; say qq[|$s|];" |monks| 12:51 >
See perlre#Modifiers.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re^5: combining lists along with a regex
by Athanasius
in thread combining lists along with a regex
by Aldebaran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |