in reply to modifying the search pattern of a file.

Just have to throw in a one-liner here, since there are command-line switches for this very thing.

perl -i -pe 's/(<% INCLUDE file)(1|2)(\.txt %>)/$1 . ($2 == 1 ? 2 : 1) + . $3/eg' index.txt

*Woof*