my %ips; # This is a hash while () { # Read em in $ips{$1}++ if (/^(\d+\.\d+\.\d+\.\d+)\s-\s-/); # no dot star # I make no promises that the above is a valid # IP matcher. It will match IPs and other # things too.. } foreach my $ip (keys %ips) { # Print em out print "IP $ip $ips{$ip}\n"; }