In this episode, Kirk and an away team go to another planet they find uninhabited except for a millennia-old man who claims to have been various figures in Earth's history, including Alexander the Great (and possibly Julius Caesar, I'm not sure).
This is Requiem for Methuselah.
Here's Memory Alpha's brief synopsis of the episode:
While the Enterprise searches for the rare cure to a deadly disease, the landing party is confronted by a reclusive man who is willing to kill to preserve his privacy.
And here's the actual dialogue from the relevant scene:
MCCOY: Physically human but not human. These are earlier versions of Rayna, Jim. She's an android.
FLINT: Created here by my hand. Here, the centuries of loneliness were to end.
SPOCK: Your collection of Leonardo da Vinci masterpieces, Mister Flint, they appear to have been recently painted on contemporary canvas with contemporary materials. And on your piano, a waltz by Johannes Brahms, an unknown work in manuscript, written in modern ink. Yet absolutely authentic, as are your paintings.
FLINT: I am Brahms.
SPOCK: And da Vinci?
SPOCK: How many other names shall we call you?
FLINT: Solomon, Alexander, Lazarus, Methuselah, Merlin, Abramson. A hundred other names you do not know.
SPOCK: You were born?
FLINT: In that region of earth later called Mesopotamia, in the year 3834 BC, as the millennia are reckoned. I was Akharin, a soldier, a bully and a fool. I fell in battle, pierced to the heart and did not die.
MCCOY: Instant tissue regeneration coupled with some perfect form of biological renewal. You learned that you were immortal and
FLINT: And to conceal it. To live some portion of a life, to pretend to age and then move on before my nature was suspected.
SPOCK: Your wealth and your intellect are the product of centuries of acquisition. You knew the greatest minds in history.
FLINT: Galileo, Socrates, Moses. I have married a hundred times, Captain. Selected, loved, cherished. Caressed a smoothness, inhaled a brief fragrance. Then age, death, the taste of dust. Do you understand?
SPOCK: You wanted a perfect, ultimate woman, as brilliant, as immortal as yourself. Your mate for all time.
FLINT: Designed by my heart. I could not love her more.
Star Trek: The Original Series S03E21 "Requiem for Methuselah"