I noticed you used the s modifier in your match and that you seem to be trying to match across the whole file.

This example might not be the most efficient way but is a start.

use warnings; use strict; my @terms = qw( Maple Oak walnut pine juniper ); my $text; { #slurp the whole file local $/; $text = <DATA>; } if ( $text =~ /upperboundary(.+)lowerboundary/s ) { $text = $1; print $text, "\n\n"; } else { die "no match"; } foreach my $term (@terms) { if ( $text =~ /($term)/is ) { print "$1\n"; } } __DATA__ upperboundary The book Hiking the Red, A Complete Trail Guide To Kentucky's Red Rive +r Gorge made it a point to describe the habitat and the diverse species of tre +es that one is likely to encounter at the Red. According to the authors, the s +pecies of trees found in the Daniel Boone National Forest includes beech, sug +ar maples, white pines, hemlock, several types of oak, and hickory. These + trees provide habitat for an estimated 67 different species of reptiles and amphibians, 46 species of mammals, and 100 species of birds. lowerboundary

Edit: The text is from http://www.redrivergorge.com/dbnf.html.


In reply to Re: Comparing string to array elements by Lotus1
in thread Comparing string to array elements by R56

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.