for my $i (0 .. $eos) { for my $j ($min .. $max) { last if $j > $eos-$i; print substr($str, $i, $j),"\n"; } }