=over =item readline EXPR =item readline X X X Reads from the filehandle whose typeglob is contained in EXPR (or from C<*ARGV> if EXPR is not provided). In scalar context, each call reads and returns the next line until end-of-file is reached, whereupon the subsequent call returns L|/undef EXPR>. In list context, reads until end-of-file is reached and returns a list of lines. Note that the notion of "line" used here is whatever you may have defined with L>|perlvar/$E> (or C<$INPUT_RECORD_SEPARATOR> in L). See L. When L>|perlvar/$E> is set to L|/undef EXPR>, when L|/readline EXPR> is in scalar context (i.e., file slurp mode), and when an empty file is read, it returns C<''> the first time, followed by L|/undef EXPR> subsequently. This is the internal function implementing the C<< >> operator, but you can use it directly. The C<< >> operator is discussed in more detail in L. my $line = ; my $line = readline(STDIN); # same thing If L|/readline EXPR> encounters an operating system error, L|perlvar/$!> will be set with the corresponding error message. It can be helpful to check L|perlvar/$!> when you are reading from filehandles you don't trust, such as a tty or a socket. The following example uses the operator form of L|/readline EXPR> and dies if the result is not defined. while ( ! eof($fh) ) { defined( $_ = readline $fh ) or die "readline failed: $!"; ... } Note that you have can't handle L|/readline EXPR> errors that way with the C filehandle. In that case, you have to open each element of L|perlvar/@ARGV> yourself since L|/eof FILEHANDLE> handles C differently. foreach my $arg (@ARGV) { open(my $fh, $arg) or warn "Can't open $arg: $!"; while ( ! eof($fh) ) { defined( $_ = readline $fh ) or die "readline failed for $arg: $!"; ... } } Like the C<< >> operator, if a C expression is used as the condition of a C or C loop, then it will be implicitly assigned to C<$_>. If either a C expression or an explicit assignment of a C expression to a scalar is used as a C/C condition, then the condition actually tests for definedness of the expression's value, not for its regular truth value. =back