in reply to Search and replace HTML

#!/usr/bin/perl use warnings; use strict; use HTML::TreeBuilder; my $t = HTML::TreeBuilder->new_from_file(*DATA) or die qq{cant build tree: $!\n}; my $anchor = $t->look_down( _tag => q{a}, class => q{main-button}, ); $anchor->replace_with( [ q{div}, {class => qq{main-button-wrapper}}, $anchor, ], ); print $t->as_HTML(undef, q{ }); __DATA__ <html> <head> <title>search and replace</title> </head> <body> <a class="main-button" name="HrUpload" href="javascript:doUploadAtac +hment();" within="theForm"> <span>Attach</span> </a> </body> </html>
<html> <head> <title>search and replace</title> </head> <body> <div class="main-button-wrapper"><a class="main-button" href="javasc +ript:doUploadAtachment();" name="HrUpload" within="theForm"> <span>At +tach</span> </a></div> </body> </html>