Is this homework for school?
The most complex part of your problem is: You have two arrays and you want to extract only those properties of the first array that are also in the second array. Write a subroutine that accepts two array references as parameters. In that subroutine loop through the first array and for each property search the second loop (hint: grep() is good for this).
When you have that subroutine written, the rest is easy: Just write a main routine that gets the two array references and calls the subroutine