It appears that by "2D Array" you mean an array of strings, each string being a whitespace-delimited list of values.

Perl is made for this sort of thing. You could use the other answer's suggestion of splitting each line and looking at each value; however, a simple regular expression would be faster. Replace your awk line with something like this:

foreach (@grabbed)
{
#Match the beginning of the line, possibly some whitespace,
#then some digits, then more whitespace, then the contents of $value
if (/^\s*\d+\s+$value/)
{
#The line matched: do stuff
}
}

Also, will you ever need to look at the lines that don't match? If not, it would be much more efficient not to put the whole file into an array; instead, just do all of your processing in the while loop.

Thanks. I have codes later on which will use this array for different stuff. One problem though am facing now is that when I put $value = 9, it grabs lines with 9, 19, 90-99. How do I limit this ONLY till 9?
–
user1504209Aug 9 '12 at 13:21

Also, as there are similar cases for matching in different columns, won't regexp be "hard-coding" it?
–
user1504209Aug 9 '12 at 13:27

Solved it by if (/^\s*\d+\s+$position\s+/). Still would love if someone could help with a more general way to look through a column. The best would be if I could pass an argument such that "if $grabbed[$column] = ....{print the line}"
–
user1504209Aug 9 '12 at 13:32

If you really want to think of your input as columns, split each line into an array as in Birei's answer. You can also take this approach further and make a true 2D array structure using references: my @2d; while (<FILE>) { push @2d, [ split ]; } Now you can access a particular element like so: if ($2d[$row][$column] == $value) { #do stuff } This is probably the way to go if you are going to do a lot of processing on particular columns.
–
dan1111Aug 10 '12 at 7:41