in reply to compare individual string with complete array
As an aside, when you are searching an array for a particular value, using a loop, you probably want to break out of the loop once you find a match. This will ensure that you find the first hit, and it also avoids wasting time. The statement for breaking out of a loop in Perl is called last.
undef $description; foreach $col ($sheet->{MinCol} .. $sheet->{MaxCol}) { if ($sheet->{Cells}[0][$col]->{Val} eq "DESCRIPTION") { $description = $col; last; } } if (defined($description)) { ... we found a match ... }
In this example, we start by explicitly giving $description the “undefined” value. (So that, no matter what happens, we are certain as to all possibilities of what the final value might be.) Then, we begin a search. If a hit is found, the $description variable is populated, and then we immediately terminate the foreach loop. After the loop is over (one way or the other), there are now two possibilities. If $description now has a non-undefined value, then it represents the first matching entry. If it is still undefined, then no match was found.
If you choose not to use the last statement, then you will have found the last matching entry ... the hard way.