in reply to Undefined value error

I suspect the call to new returns an undefined value because it fails. The Net::SMTP docs state:
On failure undef will be returned and $@ will contain the reason for the failure.

You can try to get more information by showing $@:

$smtp = Net::SMTP->new("$servername", Debug => 1); print "$@\n";

Is $servername a valid remote host?