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