How to prompt a user for input in Perl

Home > Search > How-to

The following markup can be used to produce a prompt for user input in Perl.


print "Is the earth flat (y/n)? \n";
my $answer = <STDIN>;
chomp $answer;


The input provided in the prompt will almost always be used in an if statement.

if ($answer eq n) {
    print "Very good! You are not influenced by ridiculous media trends. \n";
} else {
    print "Try again! \n";


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter in the box below so that we can be sure you are a human.