my @pieces = m/\G(<[^>]*>|#[^#]*#|[^#<]+)/g; #### pos = 0; while (m/\G(<[^>]*>|#[^#]*#|[^#<]+)/gc) { push @pieces, $1; } die unless pos >= length;