sub get_traceroute() { my $hostname = $_[0]; my $buf = ''; if( open my $pipe, "traceroute -I -n $hostname |" ) { my $start = [gettimeofday]; while(1) { my $vin = ''; vec($vin, fileno($pipe), 1 ) = 1; if( select($vin,undef,undef,1) ) { sysread $pipe, $buf, 2048, length $buf or last; } last if tv_interval($start, [gettimeofday]) >= 2; } close $pipe; } return $buf; }