in reply to creating variables in a loop

No, you really don't want to do that. You only think you want to do that. Instead, you want a hash, with keys of "q1" through "q40". Or even an array where elements indexed 1 to 40 are your values. That'd be something like this:
my @q; for (1..40) { $q[$_] = param("q$_"); }

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.