Be careful with "trial and error programming" (also called "programming by accident"). It is always better to understand what you are doing. In this particular case, the problems are in operator precedence and in "what is truth?", both covered in detail in any Perl book or in perldoc.