in reply to pipe output to perl

See perlrun, especially about the -p and -n switches. Your code does not contain any loop and hence Perl will only print XXX two times.