while (my $line = <$fh>) { if ($line =~ m/^Part1:/ .. $line =~ m/^Part2:/) { push @array, $line; } }