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}; } #### my %elements = map { $_ => 1 } @array; foreach my $element (@array) { foreach my $tranformation (keys %transformations) { my $transformed_element = $transformations{$tranformation}->($element); if (exists $elements{$transformed_element}) { print "Found a $tranformation of $element"; } } }