#!/usr/bin/env perl use strict; use warnings; use Mojo::DOM; use Mojo::Util 'trim'; my $html = do {local $/ = undef; }; my $dom = Mojo::DOM->new($html); foreach my $div ($dom->find('div')->each) { printf "Found div with id [%s], class [%s] and content [%s]\n", $div->{'id'} // '', $div->{'class'} // '', trim($div->content // ''); } __DATA__
content here