in reply to How do I reference a variable?

I don't quite understand your question, but a small unrelated thing: Instead of doing this:
my $num = 0; for (1..5) { $num++; . . }
Do this:
for my $num (1..5) { # You can use $num in the loop, and it gets # increased automatically }
This keeps the $num variable nicely local to the loop.

Arjen