my @beginnings = ( qr{This is valid}, qr{[So]+(?:IS|isnt) this}, ); my @endings = ( qr{(?:we) Should not [be] [Pp]arsing after}, qr{either (o|f) these [Ll]ines}, ); sub isbeg { my $test = shift; foreach (@beginnings) { return undef unless $test =~ $_ } $test; } sub isend { my $test = shift; foreach (@endings) { return undef unless $test =~ $_} $test; } # here is the part I dislike, partially because of the $parsing variable # it just doesnt seem as "clean" as something some of # you would write. my $parsing; foreach my $line (@lines) { $parsing++ if isbeg( $line ); push @extracted, "$line\n" if $parsing; last if isend( $line ); }