#!/usr/bin/perl local $/; # undef input record separator my $str = ; # get all file DATA into string my @matches = $str =~ m!str1(.*?)str2!gs; print @matches; __DATA__ str1 Hello str2 str1 World str2 str1 ! str2