in reply to perl doesn't like variable
I think the problem is that you're using $counter before the use vars qw($counter) line. That line basically says "Henceforth, $counter refers to the global variable $MAIN::counter". If you refer to it before that, you get the same error as if you didn't have the use vars at all.