What is the proper way to set $1? I've created this function in my perl object: sub _die { my ($self, $message) = @_; $! = $message; return undef; } I use it like this: sub connect { my $self = shift; my $s = IO::Socket:INET->new(....) or return $self->_die("connect $!"); }