my %sort_file; open (FILE, "$data") or die $!; @all=; close (FILE); my $points_total= "/path/points_total.txt"; open FH, "$points_total" or die "Can't open $points_total: $!"; flock (FH, 1) or die "Can't lock $points_total for reading: $!"; my @fh=; close FH; #create hash of sort file foreach (@fh) { chomp; ($checkIDNumber, $total_points) = split "\t",$_; $sort_file{$checkIDNumber} = $total_points; } foreach $line (@all){ $line=~s/\n//g; ($undef,$undef,$IDNumber,$Email_address,$Page_Name)=split (/\t/,$line); if (exists ($sort_file{$IDNumber} )) { $sortfield = $total_points; } else { $sortfield = ""; } }