in reply to Re^4: Automatic IP address Generation
in thread Automatic IP address Generation

It doesn't take blank lines into consideration because you didn't mention the possibility of blank lines. Inserting the following at the start of the loop will solve that problem.
next if /^\s*\z/;