How to find and save the common words in a string to a variable

Hi guys !

I have a use case like

Ex 1 : Salman r khan and sharukh h khan
firstname : salman r and sharukh h
lastname : khan
Ex2: amithab bhachan and abishek bhachan
firstname : amithab and abishek
lastname : bhachan
Ex3 : amithab bachan
firstname : amithab
lastname : bhachan

In the above example i want to find the common words in a string like khan , bhachan how can i find that ?

Thanks in advance!!!