our $debug = 1; my $timer = 10; sub debug { if ( $debug == "1" ) { my $text = shift; print $text; } else { return 0; } } my $prline; my $print_line_sub = sub { debug ("timer triggered, running print_line_sub\n"); print $prline; }; # run command and capture output (reporting to backend) # init timer $SIG{VTALRM} = $print_line_sub; setitimer(ITIMER_VIRTUAL,1,$timer); open(my $cmd,'-|',"./test.script"); my $line=""; while ($line = <$cmd>) { $prline = $line; }