# remember that HTML::TreeBuilder inherits from HTML::Element. sub HTML::Element::strip_elements { my( $e, $tag ) = @_; $_->replace_with_content for $e->find_by_tag_name($tag); $e } # now we can write our subroutine like this: sub strip_a_elements { HTML::TreeBuilder ->new_from_content( $_[0] ) ->strip_elements('a') ->as_HTML } # and call it: my $html_minus_links = strip_a_elements( $html );