#! perl use strict; use warnings; use Text::CSV; my $csv = Text::CSV->new({ sep_char => '|' }) or die "Cannot use CSV: " . Text::CSV->error_diag; while (my $line = ) { $csv->parse($line); my @fields = grep { !/^\s*$/ } $csv->fields; print join('|', @fields), "\n"; } $csv->eof or $csv->error_diag; __DATA__ IFB Northpole||| Alaska||| 907-555-5555 Walmart||| Fairbanks||| Alaska Chicken||| Anchorage||| Alaska||| 907-555-5555 Beef||| Somewhere|||||Over the Rainbow|||907-555-5555 #### 0:31 >perl 1397_SoPW.pl IFB Northpole| Alaska| 907-555-5555 Walmart| Fairbanks| Alaska Chicken| Anchorage| Alaska| 907-555-5555 Beef| Somewhere|Over the Rainbow|907-555-5555 0:31 >