#!/usr/bin/perl -w use strict; use Data::Dumper; my $fseq = 'CCCCGCGC'; my $nsub = ['CCCCG', 'CCCGC', 'CGCGC', ]; my $result =['C----', # this is not a parameter but '----C', # intended result obtained with Dumper '---GC' ]; my @result = remove_overlap($fseq,$nsub); print Dumper \@result; # I'm not so sure how to approach # this problem with the subroutine below sub remove_overlap { my ($fseq,$nsub) = @_; my @result; my $slen = length $nsub->[0]; foreach (@{$nsub}) { # ???? my $pos = index($fseq,$_); print "$pos\n"; } return @result; } #---------- The other instances of the problem #---------- with the intended $result my $fseq2 = 'CGTGGCGC'; my $nsub2 = [ 'GTGGC', 'TGGCG']; my $result2 =[ 'G----', # intended result '----G']; my $fseq3 = 'CCGCGCTC'; my $nsub3 = [ 'CCGCG', 'CGCGC', 'GCGCT', 'CGCTC']; my $result3 = ['C----', # intended result '----C', '----T', '----C']; # No overlapping case my $fseq4 = 'AAGCTATA'; my $nsub4 = [ 'AAGC', 'TATA']; my $result4 = ['AAGC','TATA']; # intended result