open(INFILE, $file) or die "Can't open $file: $!\n"; open(OUTFILE, $file) or die "Can't open $outfile: $!\n"; # widths of the cols my @cols = qw(3 50 7 7 7 7 6 6 6 6 55 4 41 6 23 7 169); # build unpack format my $fmt = join '', map { "A$_" } @cols; # column names my @col_names = qw(mfg model spec1 spec2 spec3 spec4 opt1 opt2 opt3 opt4 desc qoh trash1 mult trash2 list trash3); while () { my %rec; $rec{@col_names} = unpack $fmt, $_; next if $rec{model} = 'COMPONENT PARTS'; print OUTFILE join('|', $rec{@col_names}) }