replace while-gets loop with IO::foreach()