Any time I see regexes and html in the same question I get a queasy feeling born of unpleasant experience. So instead of answering your question, and since ovid doesn't seem to be here just now, how about (untested):

use HTML::TokeParser::Simple; my $page = ...; my $alternative = find_alternate_page( $page ); sub find_alternate_page { my $page = shift; return undef unless $page; my $p = HTML::TokeParser::Simple->new( \$page ); my $looking = 0; while ( my $token = $p->get_token ) { $looking = 1 if $token->is_start_tag( 'noframes' ); return undef if $token->is_end_tag( 'noframes' ); if ( $looking && $token->is_start_tag( 'a' ) ) { return $token->return_attr->{href}; } } }

Decisions about which urls interest you and which don't are easy to make once the address is retrieved, and probably best done separately from the retrieval itself, since you'll be wanting to change that policy at some point.

update. tested after all. seems to work.


In reply to Re: Question Regarding Regular Expressions and Negated Character Classes by thpfft
in thread Question Regarding Regular Expressions and Negated Character Classes 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.