#!/usr/bin/perl use strict; use warnings; use Data::Dumper; # change line delimter $/ = "END"; while () { 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