#!/usr/bin/perl -w use strict; use HTML::Tree; my $doc = < This is just some text. EOF my $root=HTML::TreeBuilder->new(); $root->parse($doc); $root->eof; foreach my $n ($root->descendants) { next unless $n->tag; # skip text nodes $n->delete if $n->tag eq 'script'; } print $root->dump; # prints structure print $root->as_HTML # prints as HTML