To answer your direct question, the text captured by the parentheses is placed into $1 each time. So you can do this:
while ($page =~ /<b>(.*?)<\/b>/g) { # Now $1 contains the matched text }

However, there are a few problems with the regex itself that you should be aware of. First, you're using .*, which matches as much as it can. So if your text is "<b>foo</b> <b>bar</b>", the parentheses will capture "foo</b> <b>bar"... not what you expect. Using .*? (non-greedy) will correct that problem.

Second, you say you're matching "lines", but you're also using the /s modifier on your regex, which means that the dot will match newlines. If you don't want newlines to be able to match a dot in your regex, then don't use /s.

Third, if you're extracting data from HTML, and especially if you anticipate doing this for more than your single page of text, you'll probably want to use an HTML parser module. HTML::Parser or HTML::TokeParser are examples. Good luck!

-- Mike

--
just,my${.02}


In reply to Re: Help Pattern Matching by thelenm
in thread Help Pattern Matching 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.