# replace whatever is at columns 3,4, 8 and 9 by 'Y' s/^(...)..(...)..(...)$/$1YY$2YY$3/mg; # set the first line to 'xx' s/\G(x*)./$1x/gm;