in reply to check if an element exists in array

If the task at hand is just to check whether the name is in the file the best would probably to analyze the contents of the file directly:

my $name = 'Jim'; my $name_len = length $name; while (<STDIN>) { if (substr ($_, 0, $name_len) eq $name) { print "Jim exists!\n"; last; } }

Of course I doubt that this is the only thing you want to do with that data, but the less processing of the data you do, and the easier the solution, the faster it usually is :) But note that my code is just a concept code. If someone named 'Jimbo' would be in that file it would also match. The correct solution depends on which delimiter you use to seperate the name form the numbers.

As said in above comments: There is the rule that for low n O(n) is equal to O(1) :-) So a grep is usually fine for n =~ 100.