in reply to program doesnt work for all elements of the array

As others have asked, clean up the formatting of your post, with para and code tags. Then go back to your code and:

  1. Format with consistent indentation
  2. use strict; use warnings;
  3. Fix the warning items
  4. Fix the errors
  5. Test your corrections with perl -c wordguess.pl (or whatever name you're using for the code)
  6. Wash, rinse, repeat.
  7. When no warnings or errors are issued at 6, try to execute the program.
  8. (late addition: ) Now you're ready to insert debug statements to find your logical errors

If you get stuck, come back and show us (partially) corrected code and any msgs when you execute.