while ( ) { chomp; s/^\s+//g; my ($first, $second) = split; # now if first 'column' was blank then the second will be # in $first and $second will be undef so just swap them ($first, $second) = ($second, $first) unless $second; push @first, $first; push @second, $second; }