$SIG{ALRM} = sub { die ("Couldn't traceroute"); }; alarm (20); if ($tracert = `traceroute "$ip"`) { alarm (0); } # handle data from traceroute here