use HTML::LinkExtor; use URI; my @links = (); my $html = do { local $/; }; 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__ description image here