"If you could have driven, I would have lent you my car."
Yes, this is correct and natural sounding. In general, you don't let modal verbs into the if-clause, but can and could are exceptions. That's just how they work.
Also, because they are modals, it is not possible to create a past perfect pattern with them, so "could have driven" is the closest you can get. It still works because it's a pattern we use for imagined past.
If you want to use a past perfect pattern, then remove can/could and replace it with "be able to".
"If you were able to drive, I would lend you my car."
"If you had been able to drive, I would have lent you my car."
If you're comfortable with using the grammar from a technical perspective, then no problem. However, if you are really struggling then you could follow Jen's advice and look for good examples to follow (and accept that the examples you get are simply correct; no questions).