use strict; my @lines = map { [split /,/] } split /\s+/, <[ $i ] eq $last_line[ $i ]; # Now, empty out the elements we don't want to output again # and copy over the rest of @$line my @output = (('') x $i, @{$line}[$i..$#$line]); # Output through table module of your choice print join "|", map {sprintf "%-20s",$_} @output; print "\n"; @last_line = @$line; };