use strict; use warnings; use XML::LibXML; my $doc = XML::LibXML->new->parse_fh(\*DATA); # Your real file: # my $doc = XML::LibXML->new->parse_file('/sand/devel/sthapa/tmp/as.xcf-dist'); for my $rsc ( $doc->getDocumentElement->findnodes("//RESOURCE") ) { unless ( $rsc->hasAttribute("Id") ) { $rsc->setAttribute("Id", "AUTO-ID"); } } print $doc->serialize(1); # Or to a file- # $doc->toFile($filename); __DATA__ $(res.appl) $(res.appl)$(res.slash)all.4gm 4gs rt.2.10.01-1138 ifx msv OH HAI, I CAN HAZ ID?