in reply to Re-dimensioning an HTML table with Perl ?

You can fiddle with $COLUMS to change the table row-width

use strict; use warnings; use XML::Simple; use Data::Dumper; # read __DATA__ file into $_ { $/ = undef; $_ = <DATA>; close DATA; } # use XML::Simple to read the table string my $ref = XMLin( $_ , NoAttr=>1 ); my $tr = $ref->{tr}; my @ARR; # flatten table structure into an array for my $row (keys @{$tr}){ my @X = values @{(values %{ $tr->[$row] })[0]}; push @ARR, @X; } # now we reformat the table my $COLUMNS = 2; my $counter = 0; my %S; for my $v (@ARR){ my $i=int($counter/$COLUMNS); my $j=int($counter % $COLUMNS); push @{$S{'tr'}->[$i]->{'td'}}, $v; ++$counter; } # We use XML::Simple to transform this stucture to an xml/html string my $xml = new XML::Simple (NoAttr=>1, RootName=>'table'); # convert Perl array ref into XML document my $new_table = $xml->XMLout(\%S); # now show the result print $new_table; __DATA__ <table style="width:100%"> <tr> <th>Firstname</th> <th>Lastname</th> <th>Age</th> </tr> <tr> <td>Jill</td> <td>Smith</td> <td>50</td> </tr> <tr> <td>Eve</td> <td>Jackson</td> <td>94</td> </tr> </table>