#!/usr/bin/perl use strict; use warnings; use HTML::Parser (); my $doc = <<'EOT'; foo Howdy! EOT my $body_offset; HTML::Parser->new( start_h => [ sub { return unless shift eq "body"; $body_offset = shift; shift->eof; # tell the parser to stop }, "tagname,offset,self" ] )->parse($doc); die "No found" unless defined $body_offset; my $head = substr($doc, 0, $body_offset, ""); print $doc;