#!/usr/bin/perl use 5.016; use warnings; # 1062018 builat in same thread as #1061986 my @dump; my $false_count = 0; while (){ chomp ($_); if ($_ =~ /~\|(TOTAL.*)/ ) { my $tmp = $1; push @dump, $tmp; } else { say "False: |\"$_\"| does not match pattern"; $false_count++; } } say "\n\t DEBUG \$#dump: $#dump"; say "\t NB: last index of the array and thus 1 less than the count of array elements!\n"; say 'Counted matches-> '. ($#dump + 1) . "\tUnmatched lines-> " . $false_count; for (@dump){ say $_."\n"; } =head execution C:\> 1062018.pl False: |"~|first"| does not match pattern False: |"~|not a total 11%, "| does not match pattern False: |"FOOBAR, "| does not match pattern DEBUG $#dump: 3 NB: last index of the array and thus 1 less than the count of array elements! Counted matches-> 4 Unmatched lines-> 3 TOTAL 24.1% 0.4%, TOTAL 21.0% 0.7%, TOTAL 13.7% 10.2%, TOTAL last5 6 =cut __DATA__ ~|first ~|TOTAL 24.1% 0.4%, ~|not a total 11%, ~|TOTAL 21.0% 0.7%, FOOBAR, ~|TOTAL 13.7% 10.2%, ~|TOTAL last5 6