in reply to scalar out of a loop

As noted – define a variable, outside of the loop, and initialize it with a known value (even undef). When desired, give this variable a value and (if appropriate) jump out of the loop with last. Now, one way or the other, the variable that you've defined "has some value." And, this value isn't anyone's leftovers: it's got the value that you gave it.