$SIG{ALRM} = \&every_sec(); alarm(1); open(PROCESS, "tcpdump -ln 'filter'"|); while() { next if (!&ParseIPandCheckSomething($_)); $Counter++; } sub every_sec { print "This past second: $Counter\n"; $Counter = 0; alarm(1); } #### foreach $filter (qw(filter1 filter2 filter3)) { my $fh = FileHandle->new(); $fh->open("tcpdump -ln $filter|"); $fh->autoflush(1); push(@FHStack, $fh); } while(1) { # Read anything (up to 4096 bytes) from tcpdump foreach my $fh (@FHStack) { my $bytes = read($FH, my $buffer, 4096); $PackStack{$FH} .= $buffer; } # Process what we've gotten, looking for a complete packet foreach my $fh (@FHStack) { if ($PackStack{$FH} =~ /\n/) { # LF means completed packet received from tcpdump $PackStack{$FH} = &ProcessPacketAndRemove($PackStack{$FH}); } } }