in reply to Uninitialized value in concatenation

Using use diagnostics; in addition to use warnings; will give you more information that is sometimes helpful in debugging your problem. It is also a good practice to use strict;.

Update: something unrelated to consider: you keep opening your OUT and HEAD filehandles within your first while loop, but you do not close them until you are out of the loop.