#!/usr/bin/perl use strict; use warnings; use feature 'say'; use Mojo::DOM; my $html = ''; my $dom = Mojo::DOM->new( $html ); $dom->find('span')->each( sub { $_->content( $_->content =~ s/Spoken/Derp/r ) } ); say $dom->content;