use strict; use warnings; my @defects_to_check = qw( ATTR1 ATTR3 ATTR7 ); my $alternation = join '|(? ) { next unless /^DEFECTID/; my @defects_found = $_ =~ m/$regex/g; $total_defects += scalar @defects_found; print "defects found this line: ", (join ', ', @defects_found), "\n"; print "total defects so far: $total_defects\n"; } close $df; #### DEFECTID ATTR1 ATTR7 ATTR4 DEFECTID ATTR3 !ATTR1 DEFECTID ATTR2 ATTR5 ATTR3 DEFECTID ATTR4 DEFECTID ATTR3 #### defects found this line: ATTR1, ATTR7 total defects so far: 2 defects found this line: ATTR3 total defects so far: 3 defects found this line: ATTR3 total defects so far: 4 defects found this line: total defects so far: 4 defects found this line: ATTR3 total defects so far: 5 #### use strict; use warnings; my @defects_to_check = qw( ATTR1 ATTR3 ATTR7 ); my $alternation = join '|(? ) { next unless /^DEFECTID/; my @defects_found = $_ =~ m/$regex/g; $total_defects += scalar @defects_found; $defect_subtotals{ $_ }++ for @defects_found; } close $df; print "Found $total_defects total defects.\nDefect breakdown follows:\n"; print $_ . ":\t\t" . $defect_subtotals{$_} . "\n" for sort keys %defect_subtotals; #### Found 5 total defects. Defect breakdown follows: ATTR1: 1 ATTR3: 3 ATTR7: 1