use strict; use warnings; my $file = "file.txt"; open FH, "<", $file; while( { # do something here... } print "End of file has been reached\n";