How do I extract the domain out of an URL?

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;

Leave a Comment