in reply to matching links in a web request

$data =~ m/\<a href(.*)\<\/a\>/gs;

Regexes are greedy. This pattern will match from the first '<a href' to the last '', which is likely not what you want.

If you want to continue with your existing logic, you can try:

$data =~ m/\<a href(.*?)\<\/a\>/gs;

But, regexes might not be the best for matching this sort of thing, and actually parsing the HTML may be easier to maintain in the long run.

...

However ... in your particular case, Google doesn't like you doing this sort of thing. They used to offer accounts for people who wished to automate searching (with limits on how many searches you could run per day), but they seem to be phasing them out.

Replies are listed 'Best First'.
Re^2: matching links in a web request
by blazar (Canon) on Jun 26, 2007 at 15:26 UTC
    But, regexes might not be the best for matching this sort of thing, and actually parsing the HTML may be easier to maintain in the long run.

    Yep, there's also been a recent CUFP which if nothing else has the merit of showing how to do that easily with HTML::SimpleLinkExtor.