my %hash = map { $_ => 1 } @array; #### while (<$filehandle>) { my @row_elements = split /$pattern/; next unless $hash{$row_elements[$i]}; # Process "wanted" row here }