#assuming we have %knockknocks populated with many knock knock jokes my @setups = keys %knockknocks; my $jokekey = $setups[rand @setups];