The reason it's giving you the error is because chomp returns the number of characters removed, and in your assignment, you're telling perl to make $_ be that number, but if you remove it, the return value of chomp is discarded. $_ is only the default going IN to chomp, not out.
So, the value of $_ is undefined.
If you're wanting to assign the chomped version of $name to $_, you could say:
Code:
chomp($_ = <STDIN>);
and avoid the '$name' variable altogether, or
Code:
$_ = <STDIN>;
chomp;
to use the $_ option.
Hope this helps!