I know I should be using a module for this, but I wanna do it on my own.

While I entirely sympathise with the sentiment (ie you wanna use it as a vehicle to learn) I (and no doubt the vast bulk of the monastery) would strongly advise you not to.

The reason is that quite simply that parsing HTML is a non-trivial act. Further there are a variety of power modules available to you to do this, all of which will require you to learn stuff. Stuff which will in the long term be of far more use than learning how to parse HTML.

But in the interest of fair play I will say that

my $start = quotemeta '<!-- resultItemStart -->'; my $end = quotemeta '<!-- resultItemEnd -->'; my $string =~ m/$start(.*?)$end/s;
Might do what you want if the HTML is very simple.

Oh yes. For all intents and purposes you should assume that writing code not under strict and warnings is a crime and should be avoided at all costs...

HTH

UPDATE: Just realized I originally posted this with a dreaded .* which is a bad move. Take a look at Death to Dot Star! for why. However derekses use of .+? actually isnt good either, as it will skip an empty "record" instead of reporting it. I believe that .*? is the correct choice here. Oh and I did not capture the $start and $end because you already know what they are, dont you? :-)

Yves / DeMerphq
--
When to use Prototypes?


In reply to Re: pattern matching by demerphq
in thread pattern matching by silent11

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.