Your "issue" was that you were getting a syntax error. You now have a new issue because your syntax error is resolved. What you have now is a logic error. Unfortunately it's difficult for me to help you debug when all the code isn't here. However, something jumps out at me...
-s file - "file" is a bare word, are you using strict? You probably want -s "file" or -s $file or something.
in reply to Re: if/while/else problem
in thread if/while/else problem