in reply to Remove unwanted chars and maintain table integrity

Apart from the headers are those fixed width fields?

If they are unpack can be pressed into service to break the records into their respective fields.

This uses an array of hashes and, for the pro id fields, a AoHoA. I've used printf to reassemble the data. You may have to adjust the field widths to suit.

The debugging prints are left in if you want to see what is going on. You might want to consider what error checking you need.

#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $headers = <DATA>; my (%field, @db); while (my $record = <DATA>){ chomp $record; my ($character, $count, $length, $pro_id) = unpack(q{A29A6A7A*}, $re +cord); #print qq{*$_* } for $character, $count, $length, $pro_id; #print qq{\n}; if ($character ne q{W}){ push @db, {%field} if exists $field{character}; %field = (); $field{character} = $character; } elsif ($count ne q{W}){ $field{count} = $count; } elsif ($length ne q{W}){ $field{length} = $length; } elsif ($pro_id ne q{W}){ push @{$field{pro_id}}, $pro_id; } } push @db, {%field}; #print Dumper \@db; for my $record (@db){ printf( qq{%-29s%-6s%-7s%s\n}, $record->{character}, $record->{count}, $record->{length}, $record->{pro_id}[0], ); for (1..$#{$record->{pro_id}}){ printf( qq{%47s\n}, $record->{pro_id}[$_], ); } } # 29 6 7 5 __DATA__ Character Count Length Pro_ID Timothy Watson 12 Medulla W W W W W W ID:10 W W W ID:11 W W W ID:12 W W W ID:13 W W W ID:14 W 5 W W W W 16 W Maya Alabina 5 Exo W W W W W W ID:28 W W W ID:30 W 1 W W W W 11 W
Timothy Watson 12 Medulla 5 16 ID:10 ID:11 ID:12 ID:13 ID:14 Maya Alabina 5 Exo 1 11 ID:28 ID:30