#!/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