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}); } } }