Format & re-arrange the records

Data on my input file :

Ac1n1s1c2n2s2XPd1r1e1t1d2r2e2t2d3r3e3t3d4r4e4t4RT
Bh1k1p1h2k2p2NTq1y1f1m1q2y2f2m2q3y3f3m3q4y4f4m4ZN

and i want the output to be:

Ac1n1s1XPd1r1e1t1RT
Ac1n1s1XPd2r2e2t2RT
Ac1n1s1XPd3r3e3t3RT
Ac1n1s1XPd4r4e4t4RT
Ac2n2s2XPd1r1e1t1RT
Ac2n2s2XPd2r2e2t2RT
Ac2n2s2XPd3r3e3t3RT
Ac2n2s3XPd4r4e4t4RT
Bh1k1p1NTq1y1f1m1ZN
Bh1k1p1NTq2y2f2m2ZN
Bh1k1p1NTq3y3f3m3ZN
Bh1k1p1NTq4y4f4m4ZN
Bh2k2p2NTq1y1f1m1ZN
Bh2k2p2NTq2y2f2m2ZN
Bh3k3p3NTq3y3f3m3ZN
Bh4k4p4NTq4y4f4m4ZN

Please help me how to format these records...thank you

would you care to describe the 'algorithm' of your transformation, please.

open FH,"a.txt";
while(<FH>){
	chomp;
	my @arr=(substr($_,0,1),substr($_,1,6),substr($_,7,6),substr($_,13,2),substr($_,15,8),substr($_,23,8),substr($_,31,8),substr($_,39,8),substr($_,47,2));
	for($j=1;$j<=2;$j++){
		for($i=4;$i<=7;$i++){
			print $arr[0].$arr[$j].$arr[3].$arr[$i].$arr[$#arr]."\n";
		}
	}
}

#! /bin/ksh
open FH,"a.txt";
while(<FH>){
chomp;
my @arr=(substr($_,0,1),substr($_,1,6),substr($_,7,6),substr($_,13,2),substr($_,15,8),substr($_,23,8),substr($_,31,8),substr($_,39,8),substr($_,47,2));
for($j=1;$j<=2;$j++){
for($i=4;$i<=7;$i++){
print $arr[0].$arr[$j].$arr[3].$arr[$i].$arr[$#arr]."\n";
}
}
}

i am getting the following error!!

dd_code.sh[2]: open: not found
dd_code.sh[3]: syntax error at line 3 : `)' unexpected

please advise...

this is a 'perl' script, not a ksh script.

This works pretty well. can you explain me what is open "FH" , while"(<FH>)" and "CHOMP"..

thank you

open FH,"a.txt";
while(<FH>){
chomp;
my @arr=(substr($_,0,1),substr($_,1,6),substr($_,7,6),substr($_,13,2),substr($_,15,8),substr($_,23,8),substr($_,31,8),substr($_,39,8),substr($_,47,2));
for($j=1;$j<=2;$j++){
for($i=4;$i<=7;$i++){
print $arr[0].$arr[$j].$arr[3].$arr[$i].$arr[$#arr]."\n" > "b.txt";
}
}
}

from the above code i am trying to write the output in a file "b.txt".. i don't get any error messages but at the same time i don't see "b.txt" created...

can you help me to put /write these results in another file....

thanks in advance...