Perl – How to extract the domain out of an URL

perl

How do I extract the domain out of an URL? Is there a Perl Module? I could not find any.

Best Solution

The URI module can parse URIs for you in a nice OO-ish way. To get the domain part:

my $url = URI->new( "http://www.stackoverflow.com/" );
my $domain = $url->host;
print $domain;