$match = '0'; foreach $used_value (@used_values) { if ($value eq $used_value) { $match = '1'; last; } } if ($match == '0') { # do something }