replace while-gets loop with IO::foreach()
squeeze blank lines to further shorten this code