... code here populates normal array (@perf_array) # put the elements into a hash array for (my $k = 0; $k <= $#perf_array; $k++) { while( my ($oid, $perf) = each %values ) { if ($perf_array[$k] =~ /.*\d+\s+$perf.*/) { $perf_hash{$perf} = $perf_array[$k]; $perf_hash{$perf} =~ s/\*\s+(\d+)\s+$perf/$1/eg; $perf_hash{$perf} =~ s/\s*$//g; chomp $perf_hash{$perf}; } } } for (my $l = 0; $l <= $#perf_array; $l++) { $perf_array[$l] =~ s/\*\s+\d+\s+(.*)/$1/eg; $perf_array[$l] =~ s/\s*$//g; chomp $perf_array[$l]; while( my ($oid1, $perf1) = each %values ) { if ( $perf1 != /$perf_array[$l]/ ) { $perf_hash{$perf1} = "0"; print "$perf1 not found; set to $perf_hash{$perf1}\n"; } } }