... my $dump_thread = threads->new(\&tcp_dump, $macaddress, $dns_name); sleep 1; my $ping_thread = threads->new(\&ping, $dns_name); ... $ping_thread->join(); ... // this section checks if tcpdump captured a packet and does something with it ... my $dump_pid = `pidof tcpdump`; `kill $dump_pid`; $dump_thread->join(); ...