Matching Patterns over Multiple Lines
Up to this point we've been assuming that all the pattern matching you've been doing is for individual lines (strings), read from a file, or from the keyboard. The assumption, then, is that the string you'll be searching has no embedded line feeds or carriage returns, and that the anchors for beginning and end of line refer to the beginning and end of the string itself. For the while (<>) code we've been writing up to this point, that's a sensible assumption to make.
Quite often, however, you might want to match a pattern across lines, particularly if the input you're working with is composed of sentences and paragraphs, where the line boundaries are arbitrary based on the current test formatting. If you ...
Get Sams Teach Yourself Perl in 21 Days, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.