http://www.perlmonks.org?node_id=1002024


in reply to Perl RegEx (url explode)

Isn't URI better in this case? Bigger, but simpler code:
use URI; for (URI::->new($conf[1],"http")) { my @domain = split /\./, $_->host; my $tld = pop @domain; my $sld = join ".",@domain; my $www = @domain > 2 && $domain[0] eq "www" ? shift @domain : ""; my $host = join ".",(@domain,$tld); print ($_->scheme,$www,$host,$sld,$tld,$_->port); }
(this code will work even in weird cases like perfectly valid http://www.ru)
Sorry if my advice was wrong.