if ( /REGION/ ) { if ( /TOTAL/ ) { # Finish with that section } else { # Start with that section } } else { # Regular data line .. handle normally (see below) }