use URI; my %hostcount; while () { my $u = URI->new($_); $hostcount{$u->host}++; } foreach my $host (keys %hostcount) { print "$host = $hostcount{$host}\n"; } __DATA__ http://riverserver/dir1/dir2/index.html http://riverserver/dir1/dir2/index.html http://perlmonks.org/index.pl http://webserver.company.serv/Adir/Bdir/thePage.cfm http://riverserver/dir1/dir2/index.html http://webserver.company.serv/Adir/Bdir/thePage.cfm