in reply to How do you match for everything including newline
I've taken your code and thrown a quick example together. This code isn't anything special but it works and hopefully will point you in the right directions Treat string as single line. That is, change ``.'' to match any character whatsoever, even a newline, which normally it would not match.
Which outputs:use strict; use warnings 'all'; my @lines = ( "two three two twoone\ntwo four", "four five" ); my $old_hostname = 'two'; my $new_hostname = 'one'; my $new_file = 'filename.txt'; open(FH,'>',$new_file) || die $!; foreach my $line (@lines) { $line =~ s/(.*?)$old_hostname(.*?)/$1$new_hostname$2/sgi; print FH $line . "\n"; } close(FH);
If you need to delimit the occurences more tightly then you'll need to modify the (.*?) constructs :).one three one oneone one four four five
|
|---|