in reply to Get Domain name From URLs

while ( my $raw = <DATA> ) { next unless $raw; my $uri = URI->new($raw); print $uri->host, $/; my ( $bad_assumption_helper ) = $uri->host =~ /([^.]+)\.(?:\w\w\w|\w\w\.\w\w)\z/; print "\t", $bad_assumption_helper, "\n"; } __DATA__ http://shopping.rediff.com/ http://sportsillustrated.cnn.com/?cnn=yes http://edition.cnn.com/ http://en.wikipedia.org/ http://search.cpan.org/ http://news.bbc.co.uk/

You should heed the snark of the JavaFan though. This isn't a perfect solution and the domain name includes the TLD. A bomb-proof approach to stripping it would require quite a bit more code and probably some lookups. Anything wherein you are required to strip it probably has broken assumptions.