in reply to Re: Empty STDIN does not exit while loop
in thread Empty STDIN does not exit while loop

you can also use last unless $line; to quit the loop, but this breaks if 0 is passed. If 0 is valid you can last unless defined $line;
The last unless defined $line; statement will not work either, because even if $line is empty, it will still be defined.

Your original solution, i.e. last if $line=~/^$/; (or length $line ...), is definitely better.