in reply to Counting matches

G'day Nicpetbio23!,

Welcome to the Monastery.

As already pointed out, you'll need to be more specific to get the best answers; however, the following might get you started.

#!/usr/bin/env perl use strict; use warnings; use Data::Dump; my @src_strings = qw{A ABA ABBCCC AAABBCD BCDD CCD D}; my @re_strings = qw{A B C}; my %count; for my $src (@src_strings) { for my $re (@re_strings) { $count{$src}{$re}++ while $src =~ /$re/g; } } dd \%count;

Output:

{ A => { A => 1 }, AAABBCD => { A => 3, B => 2, C => 1 }, ABA => { A => 2, B => 1 }, ABBCCC => { A => 1, B => 2, C => 3 }, BCDD => { B => 1, C => 1 }, CCD => { C => 2 }, }

Without seeing your data, that solution could be terribly slow, or may not work (in some way or another).

See also: perlintro (and the links it provides to more detailed information); and Data::Dump (the builtin Data::Dumper module provides equivalent functionality).

— Ken