I am working on a program and need to extract TLD and web page extension from the URL
If you're using the URI module, you can easily extract the
path. Then it's a simple matter of taking everything after the last dot, or conversely removing everything up to and including the last dot. You may want to get more complicated for the extension, to properly handle cases where there is no extension.
($tld = $uri->host) =~ s/.*\.//; ($extension = $uri->path) =~ s/.*\///; $extension = '' unless $extension =~ s/.*\.//;