Q&A > CGI programming > How do you extract the server from a URL? - Answer contributed by Mr. Muskrat
Use the URI module.
my $url = 'http://www.perlmonks.org/index.pl';
my $uri = URI->new($url);
my $server = $uri->host;
print "URL: $url\n";
print "Server: $server\n";
1. Keep it simple
2. Just remember to pull out 3 in the morning
3. A good puzzle will wake me up
Many. I like to torture myself
0. Socks just get in the way
Results (346 votes). Check out past polls.