... my $active = 1; my $timeout = 20; my $an; open my $fh, "tcpdump -nn -l -e dst 224.111.111.112 and not igmp |"; $read_set->add($fh); while ($active) { my ($rh_set) = IO::Select->select($read_set, undef, undef, 1); if (defined $rh_set) { if ($_ = <$fh>) { # do some parsing on the line $an = $1; last; } else { # tcpdump died. real code will sleep 2 seconds # and then close and reopen $fh here } } if (--$timeout == 0) { $active=0; } } close $fh;