Although you have correctly made your regex non-greedy, it "can't get a match" because 1nd (in the regex) does not match 1st (in the data):

my $output = "<!-- 1st table -->What I want 1<!-- /1st table -->more s +tuff...<!-- 2st movie -->What I want 2<!-- /2st movie -->...more stuf +f...<!-- 3st movie -->What I want 3<!-- /3st movie -->...more stuff"; if ($output =~ /<!-- 1st table -->(.*?)<!-- \/1st table -->/g) { print $1; } else{ print "Nothing Here!"; }
cheerfully spits out
perl 23.pl
What I want 1
However
  1. Your /g isn't doing what your think. You've tried to specify a single set of tags. /g will find the content between them if they're repeated, but it won't find "2st sic movie
  2. Your pseudo-html makes no sense: tables without rows or data cells?
  3. Using LWP or similar, if you're not, could save you the trouble of saving the source data as a text file
  4. It's a tad peculiar to name the input FH in your code as "OUTPUT"
  5. and, if you're going to parse html, use a module. There are just too many ways to go wrong while rolling your own.

In reply to Re: Pattern Search on HTML source. by ww
in thread Pattern Search on HTML source. by Anonymous Monk

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.