my @beginnings = ( qr{This is valid}, qr{[So]+(?:IS|isnt) this}, qr{start}, ); my @endings = ( qr{(?:we) Should not [be] [Pp]arsing after}, qr{either (?:o|f) these [Ll]ines}, qr{end}, ); my ($re_begin, $re_end, $re_extract); { local $" = '|'; $re_begin = qr{@beginnings}; $re_end = qr{@endings}; $re_extract = qr{$re_begin(.*?)$re_end}s; } # is_begin and is_end are no longer needed, but # you can see how trivial they've become after # concatenating the regexes with `|' sub is_begin { shift =~ $re_begin } sub is_end { shift =~ $re_end } # extract is equally simple sub extract { shift =~ $re_extract } my $text; { local $/; $text = ; } my ($extracted) = extract $text; print $extracted; __DATA__ blah blah blah start 4 5 6 end more blah blah