open (TEMPLATE, $templatePath) || die "can't open $templatePath: $!"; my $template_tree = HTML::TreeBuilder->new(); $template_tree->parse_file (\*TEMPLATE); my $first_comment = $template_tree->look_down("_tag", "~comment"); if (not defined $first_comment) { warn "No comment found in template\n"; } prompt>perl -w test.pl No comment found in template prompt>