use HTML::LinkExtor; my @links = (); my $html = join'',; # much more elegant than => do { local $/; }; sub extract_links { my ($tag,undef,$url) = @_; if($tag eq 'a') { push @links, $url->host; } } my $p = HTML::LinkExtor->new(\&extract_links,'http://foobar.com'); $p->parse($html); print join "\n", @links; __DATA__ description image here image here