my $file = '/path/to/file.txt'; open(IN,"<$file") || die $!; read IN, my $html, -s $file; close(IN); $html =~ s/(.*?)/$1/s; #### my $flag = 0; while () { $flag = 1 if (//); $flag = 0 if (//); process_line($_) if ($flag); }