my %elements = map { $_ => 1 } @array; foreach my $element (@array) { # now construct copies of each $element # based on the patterns you describe my $transformed_element = transform($element); # then let the hash find the transformation print "Success!" if exists $elements{$transformed_element}; }