my $tld; my $url = 'http://www.someurl.com/index.html'; if($url =~ /(http:\/\/)?(.+?)\//) { my $host = $2; my @host_parts = split(/\./, $host); my $len = @host_parts; if(length($host_parts[-1]) <= 2 && $len > 2) { $tld = join('.',@host_parts[-2..-1]); } else { $tld = $host_parts[-1]; } }