#!/usr/bin/perl use strict; use warnings; my @array = qw /TATG GTTC GAAC AATA/; # DNA's tend to be loooooooooooooooong, so we create a lookup # table to calculate the reversed inverse. my %table; my @chars = qw /A C G T/; foreach my $c1 (@chars) { foreach my $c2 (@chars) { foreach my $c3 (@chars) { foreach my $c4 (@chars) { my $val = reverse my $key = "$c1$c2$c3$c4"; $val =~ y/ACGT/TGCA/; $table {$key} = $val; } } } } my %tmp; @tmp {@array} = (); my @matches = grep {exists $tmp {$table {$_}}} @array; print "@matches\n"; __END__