#!/bin/perl -w use strict; open(FILE,"myfile") or die "Couldn't open myfile"; my %first_record_hash; while () { my @array = split '|'; if ($first_record_hash{$array[0]} < 6) { #insert record into database $first_record_hash{$array[0]}++; } else { next; } }