in reply to Regex for extracting a domain name from a string.

Get your hostnames with a module like URI::Heuristic or a homemade (buggy) regex like
($host) = $uri =~ /([\w]+\.[\w]+\.[\w\.]+)/;

Then count the components with $dots = ($host =~ y/\.//); and make decisions on how much to print based on the number of dots you find.

PS: Yes, I know that regex was weak but it's just a simple example to get started. A proper module is of course suggested to have any sort of reliability for this complicated of a problem.