#!/usr/bin/perl use warnings; use strict; use XML::Twig; my $twig = XML::Twig->new( twig_handlers => { figr => sub { my $fnum = $_->att('n'); $_->del_att('n'); $_->set_tag('FIGIND'); $_->set_att(NUM => $fnum, ID => sprintf('FG.%03d', $fnum)); } } ); my $str; { local $/ = undef; $str = ; } $str = "$str"; $twig->parse($str); $str = $twig->sprint; $str =~ s!!!g; print $str; __DATA__ Nerve cells come in many shapes and sizes, but they all have a number of identifiable parts. A typical nerve cell is shown in Figure 1. Like all other cells in the body, it has a nucleus that contains genetic information. Figure 2. The cell is covered by a membrane and is filled with a fluid.