open FH, "foo" or die "Can't open foo: $!"; while () { ## current line is in $_, process it } close FH or warn "Error closing foo: $!";