Perl | Use of STDIN for Input Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Perl allows the programmer to accept input from the user to perform operations on. This makes it easier for the user to give input of its own and not only the one provided as Hardcoded input by the programmer. This Input can then be processed and printed with the use of print() function. Input to a Perl program can be given by keyboard with the use of <STDIN>. Here, STDIN stands for Standard Input. Though there is no need to put STDIN in between the 'diamond' or 'spaceship' operator i.e, <>. It is standard practice to do so. <> operator can be used to write to files as well. <STDIN> can be also be used in Scalar and List context. Syntax: $x = <STDIN>; or $x = <>; Example: Perl #!/usr/bin/perl -w use strict; use warnings; print"Enter some text:"; my $string = <STDIN>; print "You entered $string as a String"; Input: GeeksForGeeks Output: Enter some text: GeeksForGeeks You Entered GeeksForGeeks as a String In the above code, after giving Input, there is a need to press ENTER. This ENTER is used to tell the compiler to execute the next line of the code. But, <STDIN> takes this ENTER key pressed as a part of the Input given and hence when we print the line. A new line will automatically be printed after the Input string. To avoid this, a function chomp() is used. This function will remove the newline character added to the end of the Input provided by the user. Example: Perl #!/usr/bin/perl -w use strict; use warnings; print"Enter some text:"; my $string = <STDIN>; chomp $string; print "You entered $string as a String"; Input: GeeksForGeeks Output: Enter some text: GeeksForGeeks You Entered GeeksForGeeks as a StringTaking Input using just <> - Without using STDIN or stdin we can take user input just by using <>. Perl #!/usr/bin/perl print("Please enter your age : "); $age = <>; print("Your age is $age"); Comment More infoAdvertise with us Next Article Perl | STDIN in Scalar and List Context A Abhinav96 Follow Improve Article Tags : Perl Perl-Input-Output Similar Reads Perl | STDIN in Scalar and List Context STDIN in Perl is used to take input from the keyboard unless its work has been redefined by the user. Syntax: <STDIN> or <> STDIN in Scalar Context  In order to take input from the keyboard or operator is used in Perl. This operator reads a line entered through the keyboard along with t 3 min read Perl | STDIN in Scalar and List Context STDIN in Perl is used to take input from the keyboard unless its work has been redefined by the user. Syntax: <STDIN> or <> STDIN in Scalar Context  In order to take input from the keyboard or operator is used in Perl. This operator reads a line entered through the keyboard along with t 3 min read Perl | STDIN in Scalar and List Context STDIN in Perl is used to take input from the keyboard unless its work has been redefined by the user. Syntax: <STDIN> or <> STDIN in Scalar Context  In order to take input from the keyboard or operator is used in Perl. This operator reads a line entered through the keyboard along with t 3 min read Perl | File I/O Functions File handling in Perl is used to read data from an external file or to write data into an external file. This is very useful as it provides a platform to permanently store and retrieve data from files. File Handle A FileHandle associates a name to an external file, that can be used until the end of 4 min read Perl | File I/O Functions File handling in Perl is used to read data from an external file or to write data into an external file. This is very useful as it provides a platform to permanently store and retrieve data from files. File Handle A FileHandle associates a name to an external file, that can be used until the end of 4 min read Perl | File I/O Functions File handling in Perl is used to read data from an external file or to write data into an external file. This is very useful as it provides a platform to permanently store and retrieve data from files. File Handle A FileHandle associates a name to an external file, that can be used until the end of 4 min read Like