#!/usr/bin/perl use strict; use warnings; use 5.10.0; use Data::Dumper; my $beginString = "SEARCH"; my $endString = "TEST"; my $fileContent; { local $/; $fileContent = ; } if($fileContent =~ /\b$beginString\b(.*?)\b$endString\b/s){ my $result = $1; print $result; } #print Dumper($fileContent); __DATA__ #Ignoring this SEARCH => #Beginning of data I need ....... ........ #all the data I need ....... ..... #End of Data I Need TEST => # And ignoring this #### my $fileContent; open(my $fileHandler, $inputFile) or die "Could not open file '$inputFile' $!"; { local $/; $fileContent = <$fileHandler>; } close($fileHandler); #### my $fileContent = do { open(my $fileHandler, $inputFile) or die "Could not open file '$inputFile' $!"; local $/; <$fileHandler>; }; #### if($fileContent =~ /\b\Q$beginString\E\b(.*?)\b\Q$endString\E\b/s){