open LOG, "mylogfile.txt" or die "Cannot open file $!"; while () { #do some stuff with data } close LOG;