#!/usr/bin/perl -w use strict; ; #throws away first line, no need for an lvalue my %record =(); while () { next if /^\s*$/; # skip blank lines output_record() if (!/^W\s/); # just an "attempt to print" my ( $name, $count, $length, $id) = (m/^(.*?)\s{2,} (\S+) \s+ (\S+) \s+ (\S+)/x); $record{'name'} = $name if $name !~ /^W\s*$/; $record{'count'} = $count if $count !~ /^W\s*$/; $record{'length'}= $length if $length !~ /^W\s*$/; push (@{$record{'id'}},$id) if $id !~ /^W\s*$/; } output_record(); sub output_record { if (!exists($record{'name'})) { return } printf "%-30s %-3s %-3s %s\n", $record{'name'}, $record{'count'}, $record{'length'}, shift @{$record{'id'}}; foreach my $id ( @{$record{'id'}} ) { printf "%47s\n", $id; } print "\n"; #blank as spacer before next record %record=(); #record dumped, so delete it! return; } =CODE PRINTS: 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 =cut __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