yeah, lexical scope is your issue.
add the following to the top of your scripts and run them from a command line to catch things like what you are experiencing.
you should be using
if/
elsif/
else in logic chains, not just
if. it won't stop looking for matches after the first one is found otherwise.
you can also use the range (..) and smart match (~~) operators to see if a value is in a range of numbers like this:
Code:
if($rewardr ~~ [7..9]) {
...;
}