#!/usr/bin/perl use warnings; use strict; #use lib q{c:/www/lib}; #use SW::Debug; use HTML::TreeBuilder; my $html = < other stuff pic more HTML my $tb = HTML::TreeBuilder->new_from_content($html); my @images = $tb->look_down(_tag => q{img}) or die qq{look_down for img failed: $!\n}; for my $img (@images){ $img->replace_with([q{span}, {id => q{fo_big}}, $img]); } print $tb->as_HTML;