You could try to use a do { } while <LOG> loop instead of the second while (<LOG>) { }.
In reply to Re: Skip and Scan Lines by ambrus in thread Skip and Scan Lines by jc7