#!/usr/bin/perl -w BEGIN { push(@INC, $ENV{'PWD'}."/lib"); push(@INC, $ENV{'PWD'}."/lib/Spreadsheet"); } use strict; use warnings; use Getopt::Std; use Time::Local; use File::Basename; use Switch; use Data::Dumper qw(Dumper); ... $i_excelSheetName = $optionsHash{'s'} ; ... my $book = ReadData ($i_excelFileName); my @lines ; my $inLineTmp; my $sheetID = $book->[0]{'sheet'}{$i_excelSheetName}; if (! defined $sheetID) { print "\n\nError: Not found sheen name ".$i_excelSheetName." in Input Excel file.\n"; print "Available Sheets in Excel are: \n"; print Dumper \$book->[0]{'sheet'}; die "Program stopped.\n\n"; } my @rows = Spreadsheet::Read::rows($book->[$sheetID]); # Go over all lines. 'scalar' return the total number of lines. Since we should start from line 0, loop initial to 1 and we used i-1 foreach my $i (1 .. scalar @rows) { $inLineTmp = $rows[$i-1][0]; foreach my $j (1 .. scalar @{$rows[$i-1]} -1 ) { if (defined ($rows[$i-1][$j] )) { $inLineTmp .= ",".$rows[$i-1][$j]; } else { $inLineTmp .= ","; } } push @lines , $inLineTmp; }