#!/usr/bin/perl use warnings; use strict; use XML::LibXML; my $dom = 'XML::LibXML'->load_xml(location => 'file.xml'); for my $child ( @{ $dom->find('/trans-unit/*[self::source | self::target]') } ) { ( my $contents = join '', $child->childNodes ) =~ s,\n, ,g; print $contents, $child->nodeName eq 'source' ? ' || ' : "\n"; }