open(FILE,"whatever.log"); my %seen = (); while(my $line = ){ my ($first) = ($line =~ /^(/S+)/)[0]; $seen{$first}++; } print scalar keys %seen;