The top level domain is what's after the last "." of a domain, ignoring trailing ".". It's easy to find using a regex after extracting the host from the url. URI can be used to parse the url for you.
use URI qw( );
my $host = URI->new('http://www.google.co.uk/')->host();
die("No domain\n") if !defined($host) || $host =~ /^[\d.]*\z/;
my ($tld) = $host =~ /\.([^.]*)\.?\z/;
print("$tld\n"); # uk