CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
How to substract a part of url ?


New User

Jun 14, 2010, 5:17 AM

Post #1 of 2 (732 views)
How to substract a part of url ? Can't Post

I have a little problem to get only the FQDN from url string.
My url is always like
so this is relatively simple to substract first "http://www." and then everything after domain name extension.

But some of my urls are based on canonical subdomains like the following: and as subdomain is never the same string, I cannot imagine, how would be possible to get only "" from such kind of url string ?
Thanks in advance for any clues ;)


Jun 14, 2010, 11:40 AM

Post #2 of 2 (725 views)
Re: [adgort] How to substract a part of url ? [In reply to] Can't Post

My RE solves the given problem. There are almost certainly valid URLs that it would not parse correctly. For serious work, I would recommend searching CPAN for a URL parser.


use strict;
use warnings;
my @urls = (

foreach my $url (@urls) {

(my $FQDN) = $url =~ /(?:http:\/\/)?([^.]+\.\w{1,3})(?:\/\w*)?$/;
print $FQDN, "\n";

Good Luck,


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives