The simplest way of extracting stuff that straddles line boundaries would be to slurp the whole file in to memory and remove the newlines ( $data =~ tr[\n][]d; works well) before applying your regex.
However, if your files are too large to fit in memory, then you need to buffer sufficient lines to encompass your data (with the newlines stripped) to allow you to extract the data, and then discard the bits you have matched before appending more and repeating the cycle.
The following code shows one way to acheive this. As demonstrated, it reads & appends just 2 bytes at a time, until a match is found and then repeats. Hardly efficient, but it demostrates the technique rather nicely of you uncomment the print statement at the top of the outer while loop. You should be able to choose whatever size buffer suits your needs. Around 64k seems a fairly good place to start.
#! perl -slw use strict; my $re_notes = qr[<notes>.*?</notes>]; my $buffer = ''; while (sysread( DATA, $buffer, 2, length $buffer)) { $buffer =~ tr[\n][]d; # print $buffer; while($buffer =~ m[($re_notes)]og ) { print $1; } $buffer = substr($buffer, 1+rindex($buffer, '</notes>')); } __DATA__ Loads'a junk a garbage and irrelevent crap Loads'a junk a garbage and irrelevent crap Loads'a junk a garbage and +irrelevent crap Loads'a junk a garbage and <notes>This is the text I am looking for split across several lines</notes>irrelevent crap Loads'a junk a garbage and irrelevent crap Loads'a junk a garbage and +irrelevent crap Loads'a junk a garbage<notes>This is the text I am looking for on one +line embedded</notes> and irrelevent crap Loads'a junk a garbage and irrelevent crap Loads'a junk a garbage and +irrelevent crap Loads'a junk a garbage and irrelevent crap Loads'a junk a garbage and irrelevent crap Loads'a junk a garbage and +irrelevent crap Loads'a junk a garbage and irrelevent crap Loads'a junk a garbage and irrelevent crap Loads'a junk a garbage and +irrelevent crap <notes>This is the text I am looking for on one line on its own</notes +> Loads'a junk a garbage and irrelevent crap Loads'a junk a garbage and irrelevent crap Loads'a junk a garbage and +irrelevent crap Loads'a junk a garbage and irrelevent crap <notes>This is the text I am looking for split across two lines</notes> Loads'a junk a garbage and irrelevent crap Loads'a junk a garbage and irrelevent crap Loads'a junk a garbage and irrelevent crap Loads'a junk a garbage and irrelevent crap Loads'a junk a garbage and +irrelevent crap Loads'a junk a garbage and irrelevent crap Loads'a junk a garbage and irrelevent crap Loads'a junk a garbage and +irrelevent crap
Output
D:\Perl\test>256751 <notes>This is the text I am looking for split across several lines</n +otes> <notes>This is the text I am looking for on one line embedded</notes> <notes>This is the text I am looking for on one line on its own</notes +> <notes>This is the text I am looking for split across two lines</notes +>
In reply to Re: Extracting information from multiple files in a directory
by BrowserUk
in thread Extracting information from multiple files in a directory
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |