tie my @array, 'Tie::File', $filename or die "Could not open file '$filename' $!"; # First if the first line does not start with "Name" it means there isn't any headers, # add headers to the file: unshift @array, 'Name, City, State, Zip' unless $array[0] =~ /Name/; # Check the whole file if there is any blank lines, if there is, get rid of it @array = grep /\S/, @array; untie @array;