my $subdoc = PPI::Document::Fragment->new(\$sub->content); write_to_file($subdoc->serialize(), ...);