in reply to if else statement check an array
It looks like List::MoreUtils and grep are the right tools to solve your problem.
By the way, please indent your code. It's not just to make it look nicer - indenting will help you find many problems.