in reply to One loop or two

What string are you comparing? nbkid?? What does your input look like??

while(<FILE1>) { chomp; my @fields = split(/:/, $_); my $result = qx{ /opt/bin/target -e$fields[2] }; print FILE2 "$fields[0]:$fields[1]:$result:NONBKID\n"; foreach my $configParameter (keys %{$configHash}) { my $nbkid = $configHash->{$configParameter}{'nbkid'}; my $ntid = $configHash->{$configParameter}{'ntid'}; if ($ntid eq $fields[1]) { print FILE2 "$fields[0]:$fields[1]:$result:$nbkid\n"; } } }
change to
while(<FILE1>) { chomp; my @fields = split(/:/, $_); my $result = qx{ /opt/bin/target -e$fields[2] }; foreach my $configParameter (keys %{$configHash}) { my $nbkid = $configHash->{$configParameter}{'nbkid'}; my $ntid = $configHash->{$configParameter}{'ntid'}; if ($ntid eq $fields[1]) { print FILE2 "$fields[0]:$fields[1]:$result:$nbkid\n" i +f $field[3] eq $nbkid; print FILE2 "$fields[0]:$fields[1]:$result:NONBKID\n" if $fiel +d[3] ne $nbkid; } } }

maybe this is what you want? some of your information wasn't clear to me