~/sandbox$ perl -pe '$_=()=/XY[0-9]+/g;$_.="\n"' junk.txt 5 5