in reply to how to make variable forget its previous value?

I would follow both pieces of advice:

  1. Define variables locally, and within the tightest possible scope, not merely to cause them to be reinitialized but also to limit their visibility to the rest of the program.   If a variable could have an uninitialized or, worse yet, a “stale” value when accidentally seen from the wrong nearby place, eliminate such an “accident” as a possibility and turn it into a compile-time error.   (use strict; use warnings;)   Use the variable-name only once in a particular region, to avoid human-confusion, then set the lexical boundaries as tightly as makes sense, thereby maximizing the computer’s ability to stupid detect misteaks which you you will overlook...
  2. If you need to return a variable to its initial (undefined) state, use undef.   (Notice that in Perl this is not the same as a “null,” “nil,” or “empty” value.)