if (/^(Info I want.+)Start of Info/) {
print $1 ;
}
This still grabs the 'Info I want' part, which doesn't seem (despite the name) to be part of the desired info. Thus, exclude it. Meanwhile, we might as well make this a multi-line regular expression with the /m flag, so that the /./ can gobble up new-lines (which seems to be desired); explicitly notice that the Info I want and Start of Info should be on their own lines; and allow there to be nothing at all between the markers (unless we don't want that). This gives:
print $1 if ( /^Info I want$(.*)^Start of Info$/m )
(Of course, this makes the end-of-section marker 'Start of Info', which is slightly different from what the original poster said.) It's easy to gobble up leading and trailing new-lines, if they're not significant:
print $1 if ( /^Info I want\n+(.*?)\n+Start of Info$/m )
(Note the non-greedy quantifier.) Of course, this only fetches one occurrence of the info; if there might be many occurrences, then we can use a lazy quantifier as above with a while loop and the /g flag.
If the original poster can change the format of the input files, then it might be appropriate to consider changing the markers and using Text::Balanced. | [reply] [d/l] [select] |
| [reply] [d/l] |