Since you are using the <br> tag as the delimiter up to which you are getting stuff (and the next found instance of an html line break tag), you could use it to break up your data through use of $/. By that i mean something like the following:
use strict; use warnings; local $/ = "<br>"; while ( <DATA> ) { print $1 if /Title:(.*?)<br>/s; } __DATA__ a whole lot of worthless stuff <b>Title: </b> STRING_I_WANT<br> more worthless meaningless stuff or sometimes <b>Title: </b>ANOTHER STRING_I_WANT<br>

update: This should take care of the extra stuff. I reread your requirement, everything from "Title:" to <br> and did what that specified instead of just the strings you wanted. The following only retrieves those strings and shows you how to put it in a variable (basically assign $1 to something) (see rob au's response which answers the question you asked). Good luck, here is the code:

use strict; use warnings; local $/ = "<br>"; while ( my $line =~ <DATA> ) { if ( $line =~ /Title:.*?<\/b>\n?(.*?)<br>/s ){ my $saved_var = $1; print "$saved_var\n" } } __DATA__ a whole lot of worthless stuff <b>Title: </b> STRING_I_WANT<br> more worthless meaningless stuff or sometimes <b>Title: </b>ANOTHER STRING_I_WANT<br>

-enlil


In reply to Re: Help with getting everything from X until Y by Enlil
in thread Help with getting everything from X until Y 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.