#!/usr/bin/perl use strict; print qq{\n}; my $tag; while() { chomp; if ( /^\[(\w+)\]/ ... /^\w+/ ) { $tag = $1 if $1; print "<$tag>$_\n" if ( ! /^\[/ ); } } __DATA__ [DATA] data1 [ENTRY] entry here [STORY] story details [DATA] [ENTRY] another entry here [STORY] another story [KEY] [WRITER] Han Staff #### data1 entry here story details another entry here another story Han