in reply to Re^2: help required on modifying a file content
in thread help required on modifying a file content

use strict; use warnings; my @hdr; my @val; for (;;) { my $hdr_line_in = <DATA>; last unless defined $hdr_line_in; my $val_line_in = <DATA>; last unless defined $val_line_in; chomp($hdr_line_in, $val_line_in); while ($hdr_line_in =~ /([^\s\d]+(\d+))/g) { my $hdr = lc($1); my $row = $2; my $skip = $-[1]; my $val = $val_line_in =~ /^.{$skip}(\S*)/ ? $1 : ''; push(@{$hdr[$row]}, $hdr); push(@{$val[$row]}, $val); } last unless defined <DATA>; } foreach my $row (0..$#hdr) { next unless defined $hdr[$row]; print(join(',', @{$hdr[$row]}), "\n"); print(join(',', @{$val[$row]}), "\n"); } __DATA__ A1 9198 B1 C1 D1 E1 F1 23 232 233 G1 H1 I1 2222 323 A2 B2 1234 5678
outputs
a1,b1,c1,d1,e1,f1,g1,h1,i1 9198,23,232,,,233,2222,,323 a2,b2 1234,5678