#!/usr/bin/perl -w my(@handles); unlink"Results.txt"; #would loop if already present for(<*.TI>){ open($handles[@handles],$_); } open(OUTFILE,">Results.txt"); my$atleastone=1; while($atleastone){ $atleastone=0; for my$op(@handles){ if($_=readline($op)){ my@col=split; $col[1]+=0; #otherwise you print nothing but a \t if column 2 is undef print OUTFILE"$col[1]\t"; $atleastone=1; }else{ print OUTFILE"0\t"; } } print OUTFILE"\n"; } undef@handles; #closes all files close(OUTFILE);