if $a[0] has rowspan=2 then we have to place one empty in the corresponding place of $a[1] if rowspan=3 the we have to place empty in $a[1] and $a[2] in corresponding place. #### #!perl ; use strict ; use warnings ; my @a ; my @b ; my @c ; my @splitted ; my $i ; my $j ; my $aref ; $a[0] = "Target proteinPurified protein concentrationActivity" ; $a[1] = "Mg/liter cultureMg/g dry cell weight" ; $a[2] = "Mg/liter cultureMg/g dry cell weight" ; # First build an array of array foreach $i (0..$#a) { @splitted = $a[$i] =~ m#(.*?)#g ; $b[$i][$_] = shift @splitted for (0..$#splitted ) } # Apply rules $aref = $b[0]; for $j ( 0 .. $#{$aref} ) { if ( $b[0][$j] =~ m/rowspan=(\d)/ && $1 == 2 ) { $b[1][$j] = "" . $b[1][$j] ; } elsif ( $b[0][$j] =~ m/rowspan=(\d)/ && $1 == 3 ) { $b[1][$j] = "" . $b[1][$j] ; $b[2][$j] = "" . $b[2][$j] ; } } # Merge into a simple array for $i ( 0 .. $#b) { $aref = $b[$i]; $c[$i] = join "", @$aref ; } # Format and print result foreach (@c) {$_ =~ s##\n#g; print $_, "\n\n" ; } #### Target protein Purified protein concentration Activity Mg/liter culture Mg/g dry cell weight Mg/liter culture Mg/g dry cell weight