for ( $loop=0; $loop=4; $loop++) { use LWP::UserAgent; use HTML::LinkExtor; use URI::URL; $url = "http://www.prnewswire.com"; $ua = new LWP::UserAgent; my @img = (); sub callback { my($tag, %attr) = @_; return if $tag ne 'a'; # we only look closer at written documents, not images push(@img, values %attr); } $p = HTML::LinkExtor->new(\&amp;amp;amp;amp;amp;amp;amp;amp;amp;callback); $res = $ua->request(HTTP::Request->new(GET => $url), sub {$p->parse($_[0])}); my $base = $res->base; @img = map { $_ = url($_, $base)->abs; } @img; splice(@img,-20); $links = join(",", @img), "\n"; $count++ while $links =~ /http/gsm; for ($i = 0; $i < $count; $i++) { use LWP::Simple; $body = get("@img[$i]"); if ($body =~ /inmx/gsmi) { $mailprog = '/usr/sbin/sendmail'; $recipient = 'xx@here.com'; open (MAIL, "|$mailprog -t"); print MAIL "To: $recipient\n"; print MAIL "$body\n"; } } }