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 }++; } } }
In reply to Re^4: search text file
by jwkrahn
in thread search text file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |