#!/usr/bin/perl use strict; use warnings; use Mojo::DOM; # slurp in from file, or get using Mojo::UserAgent... my $html = '

This is sentence 1

This is sentence 2

This is sentence 1. This is sentence 3

'; # new Mojo::DOM my $dom = Mojo::DOM->new( $html ); # for each p tag found for my $e ( $dom->find('p')->each ){ # use the all_text method to get all of the visible text, including from # descending tags. In this short example to get you started match a specific # string. if ( $e->all_text eq 'This is sentence 2' ){ # once we have a match, wrap the node around this: $e->wrap_content(''); } } # print to screen, do whatever you want with the results. print $dom->content;