1.txt @gi AGAT + AAAA 1:1.txt @gi CATT + AAAAA 3:1.txt #### 2.txt @gi AGAT + AAAA 1:2.txt @gi TACA + AAAA 2:2.txt #### output.txt @gi AGAT + AAAA 2 1:1.txt 1:2.txt @gi CATT + AAAAA 3 3:1.txt @gi TACA + AAAA 2 2:2.txt #### #!/usr/bin/env perl use strict; use warnings; my %compare; $/=""; my $key; my $value; while (<>) { chomp; ( $key, $value ) = split('\t', $_); my @lines = split /\n/, $key; my $key1 = $lines[1]; push( @{ $compare{$key1} }, $value ); } foreach my $key1 ( sort keys %compare ) { my $tot = 0; my $file_count = @ARGV; for my $val ( @{$compare{$key1}} ) { $tot += ( split /:/, $val )[0]; } if ( @{ $compare{$key1} } >= $file_count) { print join( "\t", $key, $tot, @{ $compare{$key1} } ), "\n\n"; } }