Yes, you can do that. If you don't need a visa, leaving and entering repeatedly is not a problem at all, as long as you don't exceed the 90 days in any 180-day period maximum (if you would need a visa, it would be possible as well but would be contingent on the number of entries allowed on your visa).
Note that it's a rolling 180-day period, you cannot come back for the last 18 days and then start another 90-day stay, it's more complicated than that. The EU commission provides a calculator to help you figure out how it works in practice and how many days are left.
The only thing is that if you only have a couple of days left, you might want be prepared to explain your plans to show the border guard you understand the rules and you are not planning on overstaying (only if they ask of course, which they might very well not do!).