in reply to why the 2nd program doesn't work?

Try:
... print chomp($x=<STDIN>); ...
it returns 1 !

From "Programming Perl":
Unlike chop, chomp returns the number of characters deleted.