#!/usr/bin/perl -- ## ## ## ## perltidy -olq -csc -csci=3 -cscl="sub : BEGIN END if " -otr -opr -ce -nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr -ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use Path::Tiny qw/ path /; use POSIX(); use autodie qw/ close /; Main( @ARGV ); exit( 0 ); sub Main { my $date = POSIX::strftime( '%Y-%m-%d', localtime ); my $bak = "$date.bak"; my @xml_files = path( $directory )->children( qr/\.xml$/ ); for my $file ( @xml_files ) { Diddle( $file, "$file-$bak" ); } } ## end sub Main sub Diddle { my( $in, $bak ) = @_; path( $in )->move( $bak ); my $infh = path( $bak )->openr_raw; my $outfh = path( $in )->openrw_raw; while( <$infh> ) { s{&}{&}g; ## will match more than what you want fix it s{&amp;}{&}g; s{\s>\s}{>}g; s{\s<\s}{<}g; print $outfh $_; } close $infh; close $outfh; } ## end sub Diddle