sub pars0r{ my $b_got_match = 0; # Initialize boolean to FALSE foreach my $volume (@raw_data) { if ($volume =~ /$vol_to_parse/){ if (!$b_got_match) { # Only print the match once, as $b_got_match gets # set once we print it, and then this conditional # will never again get executed. ## print "$vol_to_parse got got\n"; $b_got_match = 1; } # We can still track the total number of matches ++$counter; } } }