if( $! == ECONNREFUSED() ) { ...connection was refused... } elsif( $! == ETIMEDOUT() ) { ...connection timed out... } else { ...some other error... }