foreach my $line () { if ($line =~ /PatternBegin/ .. /PatternEnd/) { $str .= $line; } }