τ τ τ #### #!/usr/bin/perl use strict; use warnings; use Mojo::DOM; use Mojo::File; # read the xml file my $source = Mojo::File->new( 'source.xml' ); my $xml = $source->slurp; # use Mojo::Dom to parse the XML my $dom = Mojo::DOM->new->xml(1)->parse( $xml ); # for each inline-formula id in the file for my $e ( $dom->find('inline-formula[id]')->each ){ # create file named value_of_id.mml my $file = "$e->{id}.mml"; my $path = Mojo::File->new( $file ); # write contents to file $path->spurt( $e->to_string ); } #### -rw-rw-r-- 1 marto marto 131 Dec 4 10:17 ieqn-3.mml -rw-rw-r-- 1 marto marto 131 Dec 4 10:17 ieqn-2.mml -rw-rw-r-- 1 marto marto 131 Dec 4 10:17 ieqn-1.mml marto@Shemp:~/code/perlmonks$ cat ieqn-1.mml τ marto@Shemp:~/code/perlmonks$ cat ieqn-2.mml τ