in reply to Until there's nothing but spaces?

not exactly sure what your

print line until ( !($line =~ /\s+/ ) )

means, but here's a pseudocode that I _think_ is close to what you want:

while( my $ln = <$filehandle> ) { next if $ln =~ /^\s*$/; if( $ln .... [ your conditions ] ) { while( $ln = <$filehandle> ) { last if $line =~ /\s*$/; print $line; # or whatever } } }