When you read in a line, it includes the newline "\n" at the end of the string and thus your string comparison does not work. By contrast, conversion to a number drops the newline, so your numerical comparison does work. To fix it, use chomp:
chomp( $guess = $_);