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