# open my $fh, '<', $file_path or die "unable to read $file_path" # list context: every line goes in the array my @all_lines = <$fh>; # scalar context: just next line goes into a scalar (<> acts as an iterator here) my $line = <$fh>; # so to read a file one line at time: while (defined( my $line= <$fh>)) {