in reply to can not flush stdout

First problem is the first line:
#!/usr/bin/perl -p
You really don't want the -p option here ... from perlrun:
-p causes Perl to assume the following loop around your program, which makes it iterate over filename arguments somewhat like sed: LINE: while (<>) { ... # your program goes here } continue { print or die "-p destination: $!\n"; }
that's why you need to enter a carriage return. If there are no arguments, the while(<>) idiom will open and read STDIN.

-derby