use warnings; use strict; use Mojo::DOM; my $html = q{}; my $insert = q{}; my $dom = Mojo::DOM->new($html); $dom->find('head')->each(sub { $_->child_nodes->first->prepend($insert) }); print "$dom\n"; __END__