The pronoun “who" is the subject pronoun. The pronoun “whom" is the object pronoun. Because “who" and “whom" are each used in different circumstances, you must determine if the modifier is performing the action in the relative clause or receiving the action. Let's look at some examples:
1. This is the person who wrote the book.
2. This is the person whom I saw at the book store.
First, find your relative clause “who wrote the book" or “whom I saw at the book store" and determine if the verb has a subject.
In the first example, it doesn't: thus we must use the subject pronoun “who" In the second example, the verb “saw" has a subject “I" performing the action: therefore we use the object pronoun “whom" because it is receiving the action. Let's look at some more difficult examples.
3. The woman who lived next door for fifteen years is studying to become a doctor.
4. The woman whom I lived with for fifteen years is studying to become a doctor.
In both examples above, the relative clause is in the middle of the sentence. In the first example it is the “woman" performing the action: use the subject pronoun “who" In the second example, the subject “I" is performing the action and the “woman" is receiving the action: use the object pronoun “whom"