$ echo 'package Tom;' > foo.pl
$ chmod u+x foo.pl
$ ./foo.pl
package: not found
This is where splain comes in handy.
$ ./foo.pl 2>&1 | splain
package: not found (#1)
(A) You've accidentally run your script through the
Bourne shell instead of Perl. Check the #! line, or
manually feed your script into Perl yourself.
Your mistake in posting was to say "my code looks something like this, it gives some errors" and then go into a long tangent about what you THINK might be causing the errors. Much better is to say "here's the exact code, here is what I expected it to do, and here is the exact error I got." Smart Questions HOWTO.
(The mystery of how somebody who doesn't understand that #! is parsed by the shell got a job adminning 800 Linux boxes is left as an exercise to the reader.)