$i = 0; @no = qw(one two three four five); foreach ( @no ){ s/e/foo.$i/ && $i++ while /e/; } print "@no\n"; __END__ onfoo.0 two thrfoo.1foo.2 four fivfoo.3