#!/bin/perl open(IN,"file1"); open(IN2,"file2"); open (OUT,"> output"); while($str=) { @array=split(/\s+/,$str); while($data=) { @box=split(/\s+/,$data); foreach $item(@array) { splice (@box,2,0,"$array($item)"); print OUT "@box\n"; } } }