$file = "c:\\temp\\1.xml"; $out = "c:\\temp\\output.txt"; open (FH, $file)or die "Cannot Open $file :$!"; open(OUT, ">$out")or die "Cannot Open $out :$!"; while() { s/^.*(<.*>)//g; s/(?<=\w) (?=\w)//g; s/\n\n/\n/g; s/ / /g; print OUT $_; } close FH; close OUT;