$|=1; # So it works in the IDE
$a = 6; # My number to guess

print "Guess the number!\n";
while(defined($n = <STDIN>)){
  chomp $n;

  last if $n eq "quit"; # has to be before the check if a number is entered!

  unless ($n =~ /^-?\d+$/){ # this also allows for negative numbers
    print "Please enter a number!\n";
    next;
  }

  if ($n > $a){ # Check the number and report the results to the user
    print "Your number is too high!\n";
  }
  elsif ($n < $a){
    print "Your number is too low!\n";
  }
  else { # Here it has to be $n == $a
    print "You guessed it!\n";
    last; # Don't get any more input!
  }
}
