Your inner loop substitutes 11 for every 10 found in @input
So the next time the outer loop runs, and increments i, all the matches and substitutions have already been done,
There will never be a 10 to match in the inner loop after the first run. The if statement is never true. The printed i is always 11.
example containing 3 x 10, and showing the array after each pass of the inner loop.
Code:
#!/usr/bin/perl
@input = qw(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 10 98 15 13 10);
print "@input\n";
for ($i=11; $i<=20; $i++) {
foreach my $line (@input) {
if ($line =~ /10/) {
$line =~ s/10/$i/;
print $line . "\n";
}
}
print "iteration $i : @input\n";
}
Gives the output :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 10 98 15 13 10
11
11
11
iteration 11 : 1 2 3 4 5 6 7 8 9 11 11 12 13 14 15 16 17 18 19 20 11 98 15 13 11
iteration 12 : 1 2 3 4 5 6 7 8 9 11 11 12 13 14 15 16 17 18 19 20 11 98 15 13 11
iteration 13 : 1 2 3 4 5 6 7 8 9 11 11 12 13 14 15 16 17 18 19 20 11 98 15 13 11
iteration 14 : 1 2 3 4 5 6 7 8 9 11 11 12 13 14 15 16 17 18 19 20 11 98 15 13 11
iteration 15 : 1 2 3 4 5 6 7 8 9 11 11 12 13 14 15 16 17 18 19 20 11 98 15 13 11
iteration 16 : 1 2 3 4 5 6 7 8 9 11 11 12 13 14 15 16 17 18 19 20 11 98 15 13 11
iteration 17 : 1 2 3 4 5 6 7 8 9 11 11 12 13 14 15 16 17 18 19 20 11 98 15 13 11
iteration 18 : 1 2 3 4 5 6 7 8 9 11 11 12 13 14 15 16 17 18 19 20 11 98 15 13 11
iteration 19 : 1 2 3 4 5 6 7 8 9 11 11 12 13 14 15 16 17 18 19 20 11 98 15 13 11
iteration 20 : 1 2 3 4 5 6 7 8 9 11 11 12 13 14 15 16 17 18 19 20 11 98 15 13 11