Keep it simple: use
set_att instead of id_seed and format the id value as you want:
#!/usr/bin/perl
use strict;
use XML::Twig;
my $string = '<xml>
<p>here the paragraph comes</p>
<p>here the paragraph comes</p>
<p>here the paragraph comes</p>
<p>here the paragraph comes</p>
<a>here the paragraph comes</a>
<a>here the paragraph comes</a>
<a>here the paragraph comes</a>
<a>here the paragraph comes</a>
<a>here the paragraph comes</a>
<a>here the paragraph comes</a>
<a>here the paragraph comes</a>
<a>here the paragraph comes</a>
<a>here the paragraph comes</a>
<a>here the paragraph comes</a>
<a>here the paragraph comes</a>
<a>here the paragraph comes</a>
</xml>';
my $i;
my $j;
my $twig = new XML::Twig(
twig_handlers => {
p => sub { $_->set_att(id => sprintf "fig%02d", ++$i) }, #gene
+rate id
a => sub { $_->set_att(id => sprintf "sec%02d", ++$j) }, #gene
+rate id
},
pretty_print => 'indented' #print format
);
$twig->parse($string);
$string = $twig->sprint;
print $string;