in reply to count the number of occurrences of a pattern in a file

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

(not what your code does, but what you ask for in the subject line)

Replies are listed 'Best First'.
Re^2: count the number of occurrences of a pattern in a file
by johngg (Canon) on Apr 20, 2010 at 22:35 UTC

    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