#!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" ; }