in reply to Oddly growing array

scalar(@lines) is one beyond the last entry in @lines. Use $#lines instead.

Caution: Contents may have been coded under pressure.