use strict; use warnings; use feature 'state'; my @files = glob "file*.tab"; my %output; foreach my $file (@files) { open my $fh, '<', $file or die $!; state $fn = -1; $fn++; while (<$fh>) { chomp; my @s = split /\t/; die "_ERROR_ not 9 colmns [$-]\n" if @s != 9; my $key = join "\t", @s[0..3]; $output{$key} = [('0') x @files] if (!exists $output{$key}); $output{$key}[$fn] = $s[6]; } close $fh; } print join("\t",'chr','fivep','threep','strand',@files),"\n"; foreach my $key (sort keys %output) { my $values = $output{$key}; my $temp_key = $key; $temp_key =~ s/[^\t]+$/ ($& eq 0) ? '+' : '-'/e; print join( "\t", $temp_key, @$values ), "\n"; }