My Code #!/usr/bin/perl my $infile1='test.txt'; my $infile2= ; my $outfile= 'output.txt'; open(INFO,"<$infile1") or die "could not open '$infile1; open(FILEA,"outputfromvariantparser1.txt") or die "could not open file"; open(FILEB,"<; while(my $line=) { chomp($line); foreach $combination(@raw_dat) { $line=~s/TEXT TO BE REPLACED/$combination/s; } print Fileb $line; }