make that: return $line unless defined $line;
theoretically the last line could be missing the newline and only contain "0". then $line would be false and ignored with your code.
Comment on Re^3: Iterator to parse multiline string with \\n terminator