You want to declare all your variables with my. Scoping issues are one of the biggest causes of hard to find bugs.
Get into the habit of declaring your variables at the smallest scope possible. See
Running a subroutine a certain number of times for a good example of scoping errors caused by not declaring variables. Get in the habit of using lexical (my'ed) variables whenever possible.
For the few global variables that you do need you and use the
our keyword to make a package global variable. See chapter 4 of the Camel book for more information
If you find yourself needing to maintain a lot of state information throughout your program you might want to consider using and OO approach. See Damian Conway's "Object Oriented Perl" for a good introduction.
Trust me, scoping seems like an unneccessary pain-in-the-ass now, but soon you will be doing it as second nature (and preaching about it to others).
-pete
"Pain heals. Chicks dig scars. Glory lasts forever."