in reply to Scoping Variables
What's going on between the assignment and the IF statement?
I would guess something is clobbering the value of $date.
Do you have a next or redo in there somewhere? Because you are blindly assigning $1 to $date regardless of a match, it sounds like maybe the loop is short circuiting and program flow comes back to the beginning of the loop and the match assigns undef to $date before hitting the IF statement.
You're not using a my $date inside the IF statement are you? That would scope the original $date out as well.
It's probably best to post the entire source for the loop it's entirety .
9 out of 10 times when I have a "bug" like that, it's usually my fault. (typo, wrong context,etc)