use strict; use warnings; use Data::Dumper; my $inputFile = \do{ "Omit this line \n" . "Foo SEARCH Part 1 \n" . "Part 2 \n" . "Part 3 TEST bar \n" . "Omit this line\n" }; my $beginString = "SEARCH"; my $endString = "TEST"; my $fileContent; open(my $fileHandler, '<', $inputFile) or die "Could not open file $! +"; { local $/; $fileContent = <$fileHandler>; } close($fileHandler); if($fileContent =~ /\b$beginString\b(.*?)\b$endString\b/s){ my $result = $1; print $result, "\n\n"; } print Dumper($fileContent); OUTPUT: Part 1 Part 2 Part 3 $VAR1 = 'Omit this line Foo SEARCH Part 1 Part 2 Part 3 TEST bar Omit this line ';
Now do you understand "post an example"?
In reply to Re: Perl reading in a file and getting a string in between two strings on different lines
by BillKSmith
in thread Perl reading in a file and getting a string in between two strings on different lines
by victorz22
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |