1. will $tree->parse_file(parse a new file) will overwrite the old parsed $tree content?
No, don't try that. You can call parse_file on a $tree only once. As far as I remember, there's no re-using it.
so that i dont have to delete the tree in the sub?
Why not just delete the tree?
As to your question here:
## why can't keep it outside ?????????????????????????/ my $literal = HTML::Element->new('~literal','text' => $insert);
I think because once you insert the $literal object into a tree, then when you later destroy the tree, that deletes that $literal object, too.
(Deleting a tree basically means deleting every attribute in every node in the tree.)
-- Sean M. Burke http://search.cpan.org/~sburke/