in reply to Loop, but print once.

What you're wanting to do is report generation, and this is old school COBOL type processing at its best. Fortunately, it's a common idiom that can be put into any procedural language, including (especially?) Perl.

You need two variables to keep up with the 1st column (the 1, 2, ...) and the 2nd column (the 300, 320, 312, ...).

$old_col_0 = ''; $old_col_1 = ''; while (<FILE>) { #containing the above information chomp; my @temp_array = split(/\t/,$_); for (1 .. 2) { #arbitary number based on outside factor my $out_line = ''; if ($temp_array[0] ne $old_col_0) { $out_line = $temp_array[0]; # Space after data $out_line .= " "; $old_col_0 = $temp_array[0]; } else { # 1 space where data would have been, plus 1 more for # column spacing $out_line = " "; } if ($temp_array[1] ne $old_col_1) { # Make sure all subsequent uses of out_line are # append, not assignment $out_line .= $temp_array[1]; $out_line .= " "; $old_col_1 = $temp_array[1]; } else { # Four spaces, 3 for data, 1 for column spacing $out_line .= " "; } # A handy join to get the rest of the data # We don't want the 0th or 1st elements, they're # handled specially. $out_line .= join(" ", @temp_array[2..5]); print $out_line;