#$col_length depends on the intial read in of the file to see how many elements in each line $count = 6; while () { @test1 = split(/ /); if ($col_length == 5) { $googlesheet->batchupdate_cell( {row => $count, col => 2, input_value => $test1[0]}, {row => $count, col => 3, input_value => $test1[1]}, {row => $count, col => 4, input_value => $test1[2]}, {row => $count, col => 5, input_value => $test1[3]}, {row => $count, col => 6, input_value => $test1[4]} ); } elsif ($col_length == 10) { $googlesheet->batchupdate_cell( {row => $count, col => 2, input_value => $test1[0]}, {row => $count, col => 3, input_value => $test1[1]}, {row => $count, col => 4, input_value => $test1[2]}, {row => $count, col => 5, input_value => $test1[3]}, {row => $count, col => 6, input_value => $test1[4]}, {row => $count, col => 7, input_value => $test1[5]}, {row => $count, col => 8, input_value => $test1[6]}, {row => $count, col => 9, input_value => $test1[7]}, {row => $count, col => 10, input_value => $test1[8]}, {row => $count, col => 11, input_value => $test1[9]} ); } elsif ($col_length == 15) { $googlesheet->batchupdate_cell( {row => $count, col => 2, input_value => $test1[0]}, {row => $count, col => 3, input_value => $test1[1]}, {row => $count, col => 4, input_value => $test1[2]}, {row => $count, col => 5, input_value => $test1[3]}, {row => $count, col => 6, input_value => $test1[4]}, {row => $count, col => 7, input_value => $test1[5]}, {row => $count, col => 8, input_value => $test1[6]}, {row => $count, col => 9, input_value => $test1[7]}, {row => $count, col => 10, input_value => $test1[8]}, {row => $count, col => 11, input_value => $test1[9]}, {row => $count, col => 12, input_value => $test[10]}, {row => $count, col => 13, input_value => $test[11]}, {row => $count, col => 14, input_value => $test[12]}, {row => $count, col => 15, input_value => $test[13]}, {row => $count, col => 16, input_value => $test[14]} ); } $count++;