#!/usr/bin/env perl use strict; use warnings; use XML::Simple; my $in_file = "in.xml"; my $xml_file = 'out.xml'; my $xml = XMLin( $in_file, KeepRoot => 1, ForceArray => 1, ); # show me what the data look like use Data::Dumper; warn Dumper $xml; ### Save a Reference to the first "attribut" tag my $ref = $xml->{importrecord}->[0] ->{aktionen}->[0] ->{transaktion}->[0] ->{aktion}->[0] ->{parameter}->[0] ->{attribut}->[0]; # add new additional attribute into the referenced tag $ref->{foo} = 'bar'; # add content via ->{content}, so now attributes are preserved and stay $ref->{content} = 'Anlegen'; XMLout( $xml, KeepRoot => 1, NoAttr => 0, OutputFile => $xml_file, );