if ($pos == $p1) { $FLAG = 1; push @temp, $red; for my $p ($p1 .. $p2) { my $s = substr($sequence, $p - 1, 1); push @temp, $s; push @temp, $brk if $p == int($p / 50) * 50; $pos++; } $pos--; # <-- ADD THIS push @temp, $span; }