in reply to Exiting from capturing output in a while?

Your method is probably quite sufficient and satisfactory, but I'm trying to get into the habit of offering alternatives. I don't think this is particularly viable for Windows, since I don't believe Perl supports the alarm() call, and I don't know how signals are supported, but something like this might also accomplish your ends:
$SIG{ALRM} = \&Done; alarm $timeout; # Set your timeout here, in secs while (<INPUT>) { print OUTPUT $_; # Do whatever } alarm 0; # So as not to trip ALRM after we're done +with INPUT close(OUTPUT); # Likewise, in case we got an EOF in INPUT + before $timeout close(INPUT); sub Done { close(OUTPUT); # Do your cleanup and optionally exit close(INPUT); exit 0; }
Correct me if I'm wrong, but once Done returns (assuming you let it), the while() loop can't continue (since the INPUT file handle is closed), so program execution could proceed normally at that point. If that's the case, you might want to localize $SIG{ALRM}. You can also use a closure instead of a sub reference for the value of $SIG{ALRM}.