# open up a process that spits out prompts and occasionally # suddenly spews screenfuls of data while () { chomp; if (/some prompt:/) { # kicked out because of the timeout # respond as appropriate ... } elsif (/first type of data/) { # kicked out because a newline was sent. ... } elsif (/second type of data/) { ... } ... }