A very slight variation, not sure if yours is clearer in meaning than mine.
perl -nle '$count += () = /XY[0-9]+/g; END {print $count}' inputfile
Cheers,
JohnGG
In reply to Re^2: count the number of occurrences of a pattern in a file
by johngg
in thread count the number of occurrences of a pattern in a file
by umasuresh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |