http://qs321.pair.com?node_id=979958


in reply to Getting lines in a file between two patterns

First I changed the default line delimiter to 'END'. Then I went through each record and did a multi-line regex to match what is between START and END.
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; # change line delimter $/ = "END"; while (<DATA>) { my $line = $_; # match REGEX across multiple lines $line =~ /START(.*)END/s; # get the match my $contents = $1; print Dumper $contents if defined $contents;; } __DATA__ XXXX YYYY START These are the first set of lines which are to be extracted END XXX ZZZ YYY START These are the second set of lines which are to be extracted END aasds tteret tertetr

Replies are listed 'Best First'.
Re^2: Getting lines in a file between two patterns
by darklord_999 (Acolyte) on Jul 05, 2012 at 08:33 UTC
    Thanks everyone. And Utilitarian's solution worked :)