in reply to Issues with Column headings

So, I am suspecting that the columnheadings were improperly read.

There's an easy way to check that. After reading the column headings, insert this code:

use Data::Dumper; print Dumper \@columnheadings;

Run your script, and see if the output matches your expectations.