use strict; use warnings; my $pid = open(my $fileHandler, '-|', "./test.exe" ); my $DONE = 0; $SIG{ALRM} = sub { $DONE = 1 }; alarm 2; while (<$fileHandler>) { print "$_\r"; # \r to not overrun output screen buffer last if ($DONE) } print "\nTimeout! - Time to kill pid: $pid\n"