sub choose { my $count = 0; my $result = undef; for( @_ ) { $result = $_ if rand() < 1 / ++$count; } $result; } my $jokekey = choose( keys %knockknocks );