May be Expect.pm is what you need. See this post: Using Expect.pm to Manage an Unreliable Program.
I've never used it myself, but in the docs I read that you can make it wait for multiple output-patterns at the same time like
$exp->expect($timeout,
[
'It worked',
sub
{
$spawn_ok = "OK";
exp_continue;
}
],
[
'-- More --',
sub
{
do_more();
exp_continue;
}
],
[
timeout =>
sub
{
print "Process timed out.\n";
}
]
);