```
Cost = (Distance / MPG) * Price per gallon
```
Plugging in the given values, we get:
```
Cost = (23 miles / 17 MPG) * $4 per gallon
= 1.35 gallons * $4 per gallon
= $5.40
```
Therefore, it will cost $5.40 to drive 23 miles at 17 MPG when gas is $4 per gallon.