in reply to Until there's nothing but spaces?

Note that $line =~ /\s+/ (or $line =~ /\s/) matches every line containing whitespace. Including something like "white space". Negating, you're looping until the first line with no whitespace at all. If you're chomping your lines (not clear from your code), that's a line consisting of a single word, not a blank one! If you're not, every line will match (the \n at the end is whitespace).

The correct thing to match is $line !~ /^\s*$/. But there's no need to negate a regexp here; instead, try looking for a line containing a non-whitespace char: $line =~ /\S/ is the idiomatic Perl for this.