What's wrong:
- No use of strict or warnings - Use strict warnings and diagnostics or die
- No use of CGI.pm - use CGI or die;
- Vast amount of global variables
- Bad looping, you should be using foreach to iterate over arrays
- Using @ary[$i] instead of $ary[$i]
- Use of 'magic numbers'
- Using loops where the exit condition may not be met - while ($gamenumber == -1)
- Complete lack of any useful comments
- Repetitive code that suggests refactoring should occur
- Using an $exitflag variable instead of last to exit a loop
- Using $#ary to determine the end of the array rather than for/foreach (see #4)
- Using " to quote and being forced to escape (\") quotes, when q/qq would help
I'm guessing that the real problem is something to do with an exit condition in one of your loops not being met.
gav^