XML::Twig->new( twig_roots => { content => \&content }, twig_print_outside_roots => 1, keep_spaces => 1, ) ->parsefile( 'ginormous.xml'); exit; sub text { my( $t, $content) = @_; my $snipped = substr($content->text, 0, 1000000); $content->set_cdata($snipped); $t->flush; }