my $file_name = ...; open(my $fh, '<', $file_name) or die("Unable to open file \"$file_name\": $!\n"); while (<$fh>) { # $_ contains a line, including the "\n". # Use "chomp;" to remove the trailing "\n". ... }