Perl (Scripting) - Prompt a user for input (stdin)

by
Jeremy Canfield |
Updated: November 29 2021
| Perl (Scripting) articles
Let's say you want to prompt a user for input, like this.
What is your name?
The following markup can be used to produce the prompt.
#!/usr/bin/perl
use strict;
use warnings;
print "What is your name? \n";
my $name = <STDIN>;
chomp $name;
In this example, whatever the user types at the prompt will be stored in a variable named $name. The $name variable can be printed to display the users name.
print "Your name is $name \n";
Did you find this article helpful?
If so, consider buying me a coffee over at