in reply to Extracting HTML between comments

First of all, do yourself a favour and install HTML::TokeParser::Simple. Your code then becomes

#!/usr/bin/perl -w use diagnostics; use strict; use HTML::TokeParser::Simple; my $filename = '/Users/peternelson/Desktop/atdstudy.html'; my $stream = HTML::TokeParser::Simple->new( $filename ) || die "Couldn't read HTML file $filename: $!"; while ( my $token = $stream->get_token ) { LOOK: { if ( $token->is_comment and $token->as_is eq '<!-- InstanceBeginEditable name="art +icle" -->' ) { goto PARSE; } else { next; } } PARSE: { if ( $token->is_comment and $token->as_is eq '<!-- InstanceEnd -->' ) { exit; } elsif ( $token->is_text ) { print $token->as_is; } next PARSE; } }

That loop doesn't work, because next doesn't work that way. You are using it inside a naked block, in which it skips execution of the rest of the block. Since the block only executes once, next LABEL is effectively the same as last LABEL. It doesn't at all affect execution flow in the surrounding loop, which seems to be what you hoped it'd do.

Your problem here is an ideal match for the flip-flop operator:

while ( my $token = $stream->get_token ) { if( ( $token->is_comment and $token->as_is eq '<!-- InstanceBeginEditable name="art +icle" -->' ) .. ( $token->is_comment and $token->as_is eq '<!-- InstanceEnd -->' ) ) { print $token->as_is if $token->is_text; } }

Makeshifts last the longest.