# controlled search-and-replace to insert column markers # using the header line as a guide to where the columns lie $headers = <>; $headers =~ s/(\S)\s/$1\#/g; while (<>) { s/\s/ (substr($headers, pos(), 1) eq '#')? '#' : ' ' /eg; @_ = split /\s*\#\s*/; # @_ now has true columns ready for whitespace trimming }