192.168.17.10 was seen 148 times http was seen 148 times 192.168.12.187 was seen 148 times ftp was seen 148 times #### #!/usr/bin/perl -w use strict; my $log = './logfile'; my (@data, @service, @dst, %count, %counts, %hash, %sizes, $dst, $service, $ip, $times); &check("192.168.47.3"); sub check { $ip = $_[0]; open (LOG, $log) or die "Can't open $log: $!"; while (){ push (@data, $_) if $_ =~ /$ip/; foreach (@data){ ($dst, $service) = (split /;/)[11,12]; next if m/^\s*$/; #skip any empty lines push(@service, $service); push(@dst, $dst); } } @service = &duplicates(@service); @dst = &duplicates(@dst); foreach (@data){ foreach my $i (@dst){ $count{$i}++; } foreach my $j (@service){ $count{$j}++; } } } while (my ($key, $count) = each(%count)){ print "$key was seen $count times\n"; } sub duplicates { my @array = @_; my %saw; @array = grep(!$saw{$_}++, @array); }