#!/usr/bin/perl
my @foo = qw(bbc.co.uk co.uk news.bbc.co.uk gla.ac.uk test.co.uk ac.uk uk);
print join(	"\n",
		sort {
			my @ad = reverse split(/\./, $a );
			my @bd = reverse split(/\./, $b );
			my ($ax, $bx);
			do {
				return 0 if ($#a == 0 and $#b == 0);
				return -1 if ($#a == 0);
				return 1 if ($#b == 0);
				$ax	= shift @ad;
				$bx	= shift @bd;
			} while (($ax cmp $bx) == 0);
			return ($ax cmp $bx);
		} @foo
	);

