$ perl -nle '$count++ while /XY[0-9]+/g; END {print $count}' inputfile