DAMN now im blinded by light!!!
Thank you very much - guess it was too obvious solution.
edit : after euphoria :D
On the other hand with the foreach loop gone the code will not check the pattern $in from the filehandle and match it with every individual line in array @ref. It will start checking if the first element in array @ matches the pattern of the first line from filehandle second from second etc. Which doesn't work for me - maybe if I'll load the filehandle <IN> into an array and to a foreach from there.