text

text

text

#### replace with #### #!/usr/bin/perl use warnings; use strict; use HTML::TreeBuilder; my $html = do{local $/;}; my $r = HTML::TreeBuilder->new_from_content($html) or die qq{new failed\n}; for my $p ($r->look_down(_tag => q{p})){ $p->replace_with( [ q{div}, {class => q{link}}, $p ] )->delete; } my @divs = $r->look_down(_tag => q{div}); my $body = $r->look_down(_tag => q{body}); $body->replace_with( [ q{body}, [ q{div}, {id => q{links}}, @divs ] ] ); print $r->as_HTML(undef, q{ }, {p => 0}); __DATA__ replace with

text

text

text