in reply to Error message while reading from file

Everyone else gave you a bad transliteration of your loop. The proper rephrasing of that is
while( my $line = <> ) { last unless $line =~ /\S/; # ... }

That is, your loop does not merely skip lines which do not contain non-blanks, it actually terminates as soon as it encounters one.

Makeshifts last the longest.