... #my $words = @words; # just use (scalar @words) chomp(my $word = lc($words[int(rand(scalar @words))])); my @chars = split//,$word; my %chars = map { $_ => 1 } @chars; ... while ($turns > 0) { ... foreach my $char (@chars) { # split not needed ... else { #my %word = map{$_=>1}split(//,$word); # not needed if (exists($chars{$guess})) { # changed %word to %chars ...