#!/usr/bin/perl use strict; use warnings; my $filecount = 25; my %count = (); my @files = map { "File $_.txt" }(1..$filecount); for my $i (0..$#files){ open IN,'<',$files[$i] or die "Could not open $files[$i] : $!"; while (){ chomp; $count{$_}[$i] += 1; } close IN; } my @result=(); print join "\t",'ID Name',@files,"\n"; for my $key (sort keys %count){ my @all = (); for my $i (0..$#files){ if (defined $count{$key}[$i]){ $all[$i] = $count{$key}[$i]; } else { $all[$i] = 0; } } print join "\t",$key,@all,"\n"; # debug # skip if any are zero next if grep( $_==0, @all ); push @result,$key; } print "\nCommon to all\n"; print "$_\n", for @result;