in reply to Scope Issue

You initialize it, and then overwrite that value again with the result of $t->waitfor(...). And that result is likely undef. You can use defined to check for undef without warnings.