- Read the file line by line
- If the line is a station identifier, save it off into (say) $state{ 'station' }
- Likewise store off $state{ 'N' } for the other lines as they're encountered
- When you find the end of a record (presumably by hitting a blank line), print the current %state and clear it.
- Lather, rinse, repeat.
Alternately if your records are delimited by blank lines you could diddle $/ and process the whole record at a time.
The cake is a lie.
The cake is a lie.
The cake is a lie.