... foreach my $k (@keywords){ my $matches_count = ( ($string =~ s/$k//ig ) ); ...