#!/usr/bin/perl use strict; use warnings; my $output = ''; my $tag; my $fh; LINE: while ( my $line = ) { chomp $line; # if line ended with a '\', remove '\' and save line for later out+put if ( $line =~ s/\\$// || $line =~ s/\s$//) { # clean indentation $line =~ s/^\s+/ /; # save line $output .= $line; next LINE; } # we have previous line(s) to consider? if ( length $output ) { # clean indentation $line =~ s/^\s+/ /; $line = $output . $line; $output = ''; } if($line =~ /^{(.*)}/) { $tag = $1; }else { if($tag eq 'FILE') { if(defined($fh)){ print $fh ""; close($fh); } my $filename = $line; open($fh, '>', "$filename.xml") or die "$filename: $!"; print $fh '',"\n"; print $fh "\n"; print $fh "$filename\n"; } elsif(defined($fh)) { if($line ne ''){ $line =~ s/\\//gi; print "<$tag>$line\n"; } } } print $line, $/; } __DATA__ {FILE} sourcetag1 {NUMBER} 00000 11111 {SOURCE} source1 {KEYWORD} {AUTHOR} author1 staff1 {HEADLINE} DISPOSABLE DECOR: THE CUTTING EDGE DULLS FAST\ TYLE AT A SPEED USUALLY ASSOCIATED WITH WARDROBE ITEMS {FILE} sourcetag2 {NUMBER} 00002 {SOURCE} sourcenam2 {KEYWORD} {AUTHOR} author2 staff2