use XML::LibXML; my $dom = 'XML::LibXML'->load_xml(IO => *STDIN); for my $child ( @{ $dom->find('/tmx/body/tu/tuv[@xml:lang=\'en\']/seg | /tmx/body/tu/tuv[@xml:lang=\'fr\']/seg | tmx/body/tu/prop | /tmx/body/tu/@creationdate') } ) { ( my $contents = join '', $child->childNodes ) =~ s,\n, ,g; print $contents, $child->nodeName eq 'source' ? "\t" : "\n"; }