#!/usr/bin/perl
#

print "Let's play a game!\n\n";

# Pick the secret number.
$number = int(rand(100));

print "I'm thinking of a number between 1 and 100.\n";
print "Try to guess what it is.\n";

# This variable controls our main loop.
$playing = 1;

while($playing) {
    print "What is your guess? ";
    $guess = <>;
    chomp $guess;

    if ($guess == $number) {
        print "You got it! Great job!\n\n";
        $playing = 0;
    }
    if ($guess < $number) {
        print "Too low.\n";
    }
    if ($guess > $number) {
        print "Too high.\n";
    }
    
}

print "All done.\n\n";


syntax highlighted by Code2HTML, v. 0.9.1