my $client_socket = new IO::Socket::INET ( [stuff] ) or die && return ( [other stuff] ); #### my $checkPort = sub { my $port = shift; if ($port) { if ($port > MAX_PORT or $port < MIN_PORT){ $error = "Please insert a correct port number (".MIN_PORT." - +".MAX_PORT.")"; return TRUE; } } else { $moduleInput{-port} = 123; return FALSE; } }; #### my $port = verify_port($value); if (defined $port) { (do stuff) } else { (handle error case) } sub verify_port { my $candidate = shift; if ( [suitable] ) { return $candidate; } else { return; } } #### my $port = verify_port($value); sub verify_port { my $candidate = shift; if ( [suitable] ) { return $candidate; } else { (handle error case) (abort execution) } }