I am not sure why you are using so much indexing.
Here is an example that demonstrates finding the two letter combinations at any point in the string.
I didn't want to have to test all the substring stuff, but this should give you an idea of how to avoid all the needless indexing.
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my @strings = ("AB", "AC", "AD", "AE", "FG"); my $counts; for my $file (glob ('File/*')) { open my $fh, "<", $file || die "Could not open $!!"; for my $line (<$fh>) { for my $string (@strings) { $counts->{$string}++ for $line =~ m/$string/g; } } close $fh; } print Dumper($counts);
In reply to Re: Reading through a file and checking for a specific string
by protist
in thread Reading through a file and checking for a specific string
by vihar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |