in reply to random variable declaration based on given count
rand would seem to be your friend e.g. sub get_val { my $n = int(rand(shift())); return "var$n" } - added to which, I would question the naming of the sub - given that it is attempting to return a var name c/w a val ?
A user level that continues to overstate my experience :-))
In Section
Seekers of Perl Wisdom