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