in reply to Re^3: search text file
in thread search text file

If you use  if ($line =~ /(\Q$domain\E)/g){ you will only get one $domain per $line.    If you want all $domain per $line then you need to use a while loop:

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

Update: Or better yet, you don't really need capturing parentheses:

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