sub get_cat { #cat stands for category, by the way my($hash,$amnt) = @_; my $code; for(@$cats) { unless($_ eq $cats->[-1]) { $code .= "int(rand($amnt-1))<$hash->{$_}?$_:" } else { $code .= "$hash->{$_};"; } } ...and I planned to eval $code, but I realized the problem } #### int(rand(99)) < 50 ? "a" : int(rand(99)) < 40 ? "b" : "c";