in reply to appending values based on criteria

Use the debugger to step through your code, and I think you will see why it doesn't work. You could replace that entire unless {} with the first print statement inside it.

You need to remember the $line the first time you see it; storing it in your hash would be a good choice.

Update: s/until/unless/

Dum Spiro Spero