in reply to Extracting domain names from FQDNs

  1. Compile a hash/array of common TLDs
    (there are several good lists out there on the web)
  2. Strip off TLD from domain (ie, .com, .co.uk, .la)
    sub.domain.tld => sub.domain
  3. Last dot-token must be domain
    sub.domain => domain
  4. Re-append TLD
    domain => domain.tld

I understand processing speed is a factor, but with a little optimization... =)

Good luck.

'kaboo

Update:
Here's a start. (I was bored.)

sub parse_fqdn { my $fqdn = shift; my @tlds = ( [qw(com net org)], # common [qw(gov edu co\.uk)], # not-so-common [qw(la li it po)] # downright odd (long list) ); foreach my $level (@tlds) { #warn "pass ". ++$pass; for(@{$level}) { return $1 if $fqdn =~ /\.(\w+?\.$_)$/; } } warn "unable to find domain from $fqdn\n"; return $fqdn; } my $domain = parse_fqdn('www.cs.niu.edu'); print "www.cs.niu.edu => $domain\n"; # niu.edu