@St.Roymond sees an issue, and I don’t have a problem with his take (Greek and Aramaic scholar that I am ; - )…
“Eternal” is a poor translation for αἰώνιον (eye-OWE-nee-own) despite how many lexicons stick to that. It indicates “age-wise”, i.e. pertaining to an age, and an age is not a specific period of time; an age lasts as long as necessary for something to be complete(d).
So let’s read it this way:
“And they will go away into age-wise punishment, but the righteous into age-wise life.”
Now ask how to determine those periods: God is just, and there is no conceivable way in which torture by fire for an unlimited amount of time is just, even for Stalin or Muslim terrorists – the Old Testament is clear that the punishment must fit the crime, so we must expect this torment to last just long enough to fit people’s worst sins.
As for the righteous, God has said He wants to live with His people. God being infinite, we can expect that His desire for this is infinite, so for the righteous we should expect that there will be no end to their age (unless God surprises us with something better).