my @tosort; while( ) { if( m|
| .. m|
| and not m|| ) { push @tosort, $_; next } print for sort splice @tosort; print }