You could combine
HTML::LinkExtor and
URI:
use HTML::LinkExtor;
use URI;
my @links = ();
my $html = do { local $/; <DATA> };
sub extract_links {
my ($tag, %attr) = @_;
next unless $tag eq 'a';
my @parts = split /\./, URI->new($attr{href})->host;
my $host = join '.', @parts[-2, -1];
push @links, $host;
}
my $p = HTML::LinkExtor->new(\&extract_links);
$p->parse($html);
print join "\n", @links;
__DATA__
<a href="http://www.foo.com">description</a>
<a href='http://www.foo.com'>image here</a>
Of course you might want to add some error checking...
gav^