while (my ($test1, $test2) = (scalar <$fh1>, scalar <$fh2>)) { last unless defined $test1 or defined $test2; ... }