#same initialization my $pid = open2( \*Reader, \*Writer, "/bin/bash" ) or warn $!; Writer->autoflush(); Reader->autoflush(); STDIN->autoflush(); $SIG{ALRM} = sub {die}; # required for alarm call below do { print ": "; # simple prompt my $cmd = ; print Writer $cmd; my $got; while (1) { eval { alarm 3; $_= }; # get line in 3 seconds or stop reading alarm 0; last if ($@ or !(defined($_))); # exit loop if there was a timeout or no data $got .= $_; } print $got; } while(1);