use strict; my @all_files = ; # angle brackets around a bareword path pattern returns all matching file names my %macs_found; for my $path ( @all_files ) { my $file = $path . ":"; $file =~ s{.*/}{:}; # now it's ":*_01day:" unless ( open( FILE, $path )) { warn "open failed on $path: $!\n"; next; } while () { chomp; $macs_found{$_} .= $file unless $macs_found{$_} =~ /$file/; } close FILE; } # Now for each mac value, see how many files had it: my $nfiles = scalar @all_files; for my $mac ( sort keys %macs_found ) { if ( split( /::/, $macs_found{$mac} ) == $nfiles ) { print "$mac found in all $nfiles input files\n"; } }