in reply to XML::Twig 'cut' and 'paste' Question

I'm wondering if you're complicating things a bit. Rather than count, and then loop, try simply looping. I have a suspicion that your cuts and pastes are changing the number of matches that //fig/label sees - once you've changed the first fig/label, it's no longer a fig/label. Try this:

#!/usr/bin/perl use strict; use warnings; use XML::Twig; my $twig = new XML::Twig( pretty_print => 'record_c' ); $twig->parsefile('1.xml'); for my $fig ( $twig->get_xpath('//fig') ) { my $label = $fig->get_xpath('./label', 0); my $caption = $fig->get_xpath('./caption', 0); next unless $label and $caption; $label->cut(); $label->paste('first_child', $caption); } $twig->print;
That seems to do the trick. Also note the better variable names ;-)