my %inventory_hash = (); open DataFile, "Inventory.csv" or die ("Inventory.csv $!"); while (my $inventory_line = ) { my @inventory_fields = split /,/,$inventory_line; my $inventory_key = shift @inventory_fields; if (exists($inventory_hash{$inventory_key})) { print "Warning! Duplicate inventory key detected: $inventory_key\n"; next; } $inventory_hash{$inventory_key} = \@inventory_fields; } close DataFile; open DataFile, "clients.txt" or die ("clients.txt $!"); while (my $line = ) { my @fields = split(/,/, $line); if (exists($inventory_hash{$fields[3]})) { my @sys = @{$inventory_hash{$fields[3]}}; # do stuff with the contents of @sys, print, whatever delete $inventory_hash{$fields[3]}; } }