$file=$ARGV[0]; open(FH,$file); open OUT1,">./$file\_rho_temp"; while(){ chomp; next if($_=~/^Gene/); @arr=split(/\s+/,$_); $rhash{$arr[0]}{$arr[3]}=$arr[4]; } @keys = keys %{$rhash{(keys %rhash)[0]}}; $format = "%1s " . ("%2s " x @keys) . "\n"; printf OUT1 $format, "Genes", @keys; foreach $key (keys %rhash) { printf OUT1 $format, $key, @{$rhash{$key}}{@keys}; }