use strict; use warnings; my $file_content = ""; my $parsed = ""; open(INPUT,"){ my $line = $_; chomp($line); $file_content .= $line; } $_ = $file_content; while(/word1(.+)word2/mg){ print "$1\n"; #This is the content between the two words }