my $outs = <<'EOS'; A B C A B D EOS # ok(2 == $outs =~ m|A|gs, "checking exactly 2 matches"); if( 2 == $outs =~ m|A|gs ){ print "exactly 2 matches\n" }