#!/usr/bin/perl use strict; use warnings; use utf8; use XML::Twig; use Data::Dumper; use File::Find; use File::Copy; use Cwd; my $dir = getcwd; my %size; my %hash; find(sub {$size{$File::Find::name} = -s if -f;}, "$dir"); foreach my $files (keys %size) { if ($files =~ /(.*)(\.xml)$/) { $hash{$1}++; } } #foreach my $x (keys %hash) #{ # print "$x\n"; #} foreach my $file (keys %hash) { my $twig = new XML::Twig(TwigRoots => {title => 1, text => 1}); $twig->parsefile("$file.xml"); open(Output, ">:utf8", "$file 2.xml") or die "can't open file $!\n"; $twig->root->print(\*Output); close (Output); }