# Store each of the 'sterren' elements into the hash FirstGroup. foreach $Element ( @sterren ) { $FirstGroup{ $Element } = 1; } # If any of the sterren elements also exist in array politici, # store that value into the hash 'Both'. foreach $Element ( @politici ) { if ( $FirstGroup{ $Element } ) $Both{ $Element } = 1; } # Finally (this step may or may not be necessary depending on what # you want to do) store the keys back into an array. @Result = keys %Both;