while (<$fh>) { chomp; if (... && !eof($fh)) { $_ .= <$fh>; redo; } ... }