my %count; while ( my $line = ) { foreach my $domain ( @list ) { while ( $line =~ /(\Q$domain\E)/g ) { $count{ $1 }++; } } }