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