#!/usr/bin/perl -w use strict; use Data::Dumper; my $s1 = 'GATTACGAGTGGCGCTCGTGTAACGGCA'; # Here are the array of the substrings, note that the number of # substrings may differ from array to array # and length of the substring may vary (defined as a parameter) my @ar = ('GATTACG','GCGCTCG','AACGGCA'); #21 (0,11,21) my @ar2 = ('GATTACG','TTACGAG','CGTGTAA'); #16 my @ar3 = ('TACGAGT','GTGGCGC','GCTCGTG'); #17 my @ar4 = ('GG','GG'); #4 score($s1,\@ar2); sub score{ my ($str,$array) = @_; my @pos; my $sub_len = length @$array[1]; foreach (@$array){ my $idx = index $s1, $_; push @pos, $idx; print "$idx\n"; } # I'm not sure where to go from here for (0..$#pos){ my $sum = $pos[$_]+$sub_len; } }