Unfortunely we don't know your solution.
But Array takes up more memory space than String. So you can convert it.
arr1 = ["firestorm", "peanut", "earthworm"]
arr2 = ["fire", "tree", "worm", "rest"]
arr1 = arr1.join(',')
And then
res = arr2.select { |word| arr1.include?(word) } #=> ["fire", "worm", "rest"]
or
res = arr2.select { |word| arr1.match?(word) } #=> ["fire", "worm", "rest"]
or
res = arr2.select { |word| arr1.match(word) } #=> ["fire", "worm", "rest"]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…