$seen(); foreach $id (@all_array){ got the name using the id to $name push (@uniquearray, $id) unless $seen{name}++;}