#!/usr/bin/perl while(){ chomp; if(/^\.\.(.*):$/) { $fh = output($output, $tag, $fh); $output = ""; $tag = $1; } $fh = output($output, $tag, $fh); } sub output { my ($output, $tag, $fh) = @_; if($output) { if($output =~ m/\.\.DN:(.*)/) { if($fh) { close($fh); } open($fh, '>', "$1.xml") or die "$1.xml: $!"; print $fh "$output"; } } return($fh); } # End of sub sroutine __DATA__ ..DN: 000044255 ..CB: ..SN: D046H6J5 ..PD: 20091030 ..DD: Friday, October 30, 2009 ..PY: 2009 ..ED: ..DN: 000044254 ..CB: ..SN: D046H6IR ..PD: 20091030 ..DD: Friday, October 30, 2009 ..PY: 2009 ..ED: