use warnings; use strict; my $data = do { open my $fh, '<', 'sample.txt' or die $!; local $/; <$fh> }; # slurp whole file into memory my $regex = qr{ ^ \s*APP>\sSTART_PARTU_8X8 \n ^ \s*APP>\sPARTITION_SPLIT \n (.*?) ^ \s*APP>\sEND_PARTU_8X8 $ }msx; if ($data=~$regex) { print $1; }