if( my $pid = open my $pipe, "traceroute -I -n $hostname |" ) { while(1) { last if ... } kill 2, $pid; close $pipe; }