in reply to misalined TABs using substr,LAST_MATCH_START/END,regex

I'd approach this differently. Instead of playing with magic variables that make the code hard to read, try to describe the algorithm in a simple way:
#!/usr/bin/perl use warnings; use strict; my $input = << "EOF"; foo\tbar\t\tbaz\tbooz\t\tqaaz\t\t\tabc foo\t\tbar\tbaz\t\tbooz\tqaaz\tabc\t123 foo\t\tbar\t\tbaz\t\tbooz\tqaaz\t\tabc EOF open my $in, '<', \$input or die $!; my @tab_counts; while (<$in>) { my $i = 0; for my $tab_count (map length, /(\t+)/g) { $tab_counts[$i] = $tab_count if $tab_count > ($tab_counts[$i] +|| 0); ++$i; } } push @tab_counts, 0; # No tab after the last field. seek $in, 0, 0; while (<$in>) { my $i = 0; print $_, "\t" x $tab_counts[$i++] for /\S+/g; print "\n"; }

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]