This should do it... I got surprised the $1 behaves differently if you loop through the array returned by /g matching, or if you stick the result of =~ in a while loop. Updated with various thoughts about this.
use warnings; use strict; use Data::Dumper; # for debugging local $/ = ""; # input separator was newline, but now it's gone -> slu +rp mode. my $html; while (<DATA>) { $html = $_; } print "Html: $html\n\n"; # just to check that this worked... it works. #Don't do this, you can't use the $1, $2 type special variables. my @matches = $html =~ m|(<B><P ALIGN=CENTER>(.+)</B></FONT>)|g; # use + | as regex delimitor to avoid leaning toothpick syndrome. print "Dumper\n" . Dumper(\@matches); # bit o debugging #Do this. Then you can access the special vars. while ($html =~ m|(<B><P ALIGN=CENTER>(.+)</B></FONT>)|g) { print "match $2\n"; # don't know why this works. $1 doesn't work. + Hm... } #outputs #match blah #match foo #match gah #$line =~ m/<B><P ALIGN\=CENTER>(.+)<\/B><\/FONT>/gm; #my $bit_i_want=$1; __DATA__ <B><P ALIGN=CENTER>blah</B></FONT> <B><P ALIGN=CENTER>foo</B></FONT> <B><P ALIGN=CENTER>gah</B></FONT>
Maybe you should be using HTML::TokeParser to do html matching, regex matching on html doesn't scale too well.

In reply to Re: Pattern Matching by tphyahoo
in thread Pattern Matching by webchalkboard

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.