in reply to ranged conditional with variable

Furthermore,
foreach (<FILE>) {
reads the whole file into memory, even though you only work on one line at a time. Use
while (<FILE>)
or (while (defined(my $line = <FILE>))) instead.