while ($HTML =~ /\G($open|$close|$comment|[^<]+)/g) { # do something with $1 }