my $input_filename = 'foo.xml'; my $temp_filename = 'bar.xml'; open my $ofh, '>', $temp_filename or die $!; open my $ifh, '<', $input_filename or die $!; while (<$ifh>) { s/foo/bar/g; print $ofh $_; } close $ifh; close $ofh; # now open $temp_filename with your XML parser