#!/usr/bin/perl use strict; use warnings; sub make_html { my $array= shift @_; my $rows= $#$array; my $cols= $#{$array->[0]}; my @html; my @last= @{ $array->[$rows] }; my @span= (1) x (1+$cols); push @html, "\n"; foreach my $row ( reverse [], @$array[0..$rows-1] ) { push @html, "\n"; foreach my $col ( reverse 0..$cols ) { if( @$row && $last[$col] eq $row->[$col] ) { $span[$col]++; } else { my $span= 1==$span[$col] ? "" : " rowspan='$span[$col]'"; push @html, "$last[$col]\n"; $span[$col]= 1; $last[$col]= $row->[$col] if @$row; } } push @html, "\n"; } push @html, "\n"; return join '', reverse @html; } my @t=( [ qw( A B C D E F H ) ], [ qw( A B C D E G I ) ], [ qw( A B C D F G J ) ], [ qw( A B C E F G K ) ], [ qw( A B D E F G L ) ], [ qw( A C D E F G M ) ], [ qw( B C D E F G N ) ], ); print make_html(\@t);