There are nine answers to this question, and there are some really interesting points about social relations in the time of Christ, or where exactly do you draw the line between being tempted by a woman and "lusting for her", but I think focusing on these issues may be missing the overall point that Jesus was trying to make in this passage.
Context
Here is the passage with a bit more context (LEB):
For I say to you that unless your righteousness greatly surpasses that
of the scribes and Pharisees, you will never enter into the kingdom of
heaven.
“You have heard that it was said to the people of old, ‘Do not commit
murder,’ and ‘whoever commits murder will be subject to judgment.’
But
I say to you that everyone who is angry at his brother will be subject
to judgment, and whoever says to his brother, ‘Stupid fool!’ will be
subject to the council, and whoever says, ‘Obstinate fool!’ will be
subject to fiery hell.
Therefore if you present your gift at the altar
and there remember that your brother has something against you, leave
your gift there before the altar and first go be reconciled to your
brother, and then come and present your gift. Settle the case quickly
with your accuser while you are with him on the way, lest your accuser
hand you over to the judge, and the judge to the officer, and you be
thrown into prison. Truly I say to you, you will never come out of
there until you have paid back the last penny!
“You have heard that it
was said, ‘Do not commit adultery.’ But I say to you that everyone who
looks at a woman to lust for her has already committed adultery with
her in his heart.
And if your right eye causes you to sin, tear it out
and throw it from you! For it is better for you that one of your
members be destroyed than your whole body be thrown into hell.
The relationship between holiness and the Kingdom of Heaven within us
There is a lot going on here, but the salient point is that what matters to God is what is happening to the inner man, in the heart. To God, there is no difference between murdering someone and hating them in your heart. Why? It makes a huge difference to us. How can these be the same? Because we are the temple of God and God lives in our hearts. So the heart must be as clean as anything happening in the holy of holies, which according to the flesh needed to be covered with gold in order to be acceptable place for the God's presence. If a priest made a small procedural error they could be instantly killed, because as you get nearer to God's presence the rules become stricter. Thus the rules as to what is in our hearts are stricter than what happens outwardly, which is the opposite of what the Pharisees taught - and what we teach today. Thus all the heart rules follow the condemnation of the pharisees.
But then which of us has a heart that is completely covered in gold (righteousness)? So who has a heart that is holy enough for the presence of God dwell therein?
Luke 17:20-21
Now when he was asked by the Pharisees when the kingdom of God would
come, he answered them and said, “The kingdom of God does not come
with things that can be observed, nor will they say, ‘Behold, here it
is!’ or ‘There!’ For behold, the kingdom of God is in your midst.”
This is a recurring theme and was a stumblingbock for those who wanted a list of outward or behavioral rules to follow, and in fact trying to know the exact boundary at which temptation turns into sin is just asking for another rule to follow.
Standards versus Rules
Thus in this interpretation, the sermon on the mount was not given so that we have new rules to follow but to show us that it is impossible for us to fulfill God's law.
Saying that whoever is angry with his brother has committed murder should lead us recognize that we have all committed murder in our hearts. It should not lead us to add a new rule to follow about trying hard to never get angry. Of course it's nice to not get angry, but this is like asking water not to be wet:
The heart is deceitful more than anything else, and it is disastrous. Who can understand it? Jer. 17.9
Indeed the summary of this portion of the sermon:
Therefore you be perfect (teleios) as your heavenly Father is perfect." (Matt 5.48) is squarely aimed at the Pharisees and others who thought that they were meeting God's standards, in order to shut them up and humble them. Thus it's not advisable to listen to the sermon on the mount from the point of view of behavioral reform, but rather as something that describes God's standard.
A key to this is in the passage on divorce (Matt 19.8-11):
He said to them, “Moses, with reference to your hardness of heart,
permitted you to divorce your wives, but from the beginning it was not
like this. Now I say to you that whoever divorces his wife, except on
the basis of sexual immorality, and marries another commits adultery,
and whoever marries her who is divorced commits adultery.” The
disciples said to him, “If this is the case of a man with his wife, it
would be better not to marry!” But he said to them, “Not everyone can
accept this saying but those to whom it has been given.
In other words, God's standards are to never support divorce unless there is infidelity. But of course it was not possible for man to meet this standard, so the actual rules that Moses gave were more lax. This means the people never met God's standard by following rules. The Hebrews never pleased God, except by faith. They never kept his commandments, and they always had wicked hearts. As do we all.
Conclusion
So Jesus in the sermon on the mount is describing God's standard, which is a standard about our heart because this is where God dwells. That standard is impossible for fallen man to meet, but we need to know what it is so that no one -- not even those who viewed themselves as keeping the law of Moses -- is not ashamed or thinks they are pleasing to God. This of course sets us up so that only Christ's righteousness can be pleasing to God and only Christ in us can be a temple in which God dwells.