modify this code to print elements that differ a x number from previous position
<p>I wrote this code to find substrings every x elements:</p>

<pre><code>print "enter file path\n";
$letters = &lt;&gt;;
chomp ($letters);

$sequence = "";

open (LETTERS, $letters) or die "error opening\n";

print "how many letters at a shot\n";
$number = &lt;&gt;;
chomp ($number);

$size = length $sequence;
chomp ($size);


for ($i = 0; $i &lt; $size; $i++) {
    $test = substr ($sequence, $i, $number);
    print "&gt; Test $i\n";
    print "$test\n";

    if ($i &gt;= $size - $number) {
    last;
    }

    }
</code></pre>

<p>so if I open a file with this string and choose x = 3:</p>

<pre><code>abcdefg
</code></pre>

<p>I get this result:</p>

<pre><code>&gt; Test 0 abc
&gt; Test 1 bcd
&gt; Test 2 cde
&gt; Test 3 def
&gt; Test 4 efg
</code></pre>

<p>Each substring differs from one position from the previous substring, I'd like to be able to control this number and dislocate the substring by 2 for example. So the result would be:</p>

<pre><code>&gt; Test 0 abc
&gt; Test 2 cde
&gt; Test 4 efg
</code></pre>

<p>Any suggestions? Thanks</p>