my $fseq6 = 'CCGCGCTC'; my @nsub6 = ( 'CCGCG', '*****', 'CGCTC' '*****',); my $fseq5 = 'CCGCGCTC'; my @nsub5 = ( 'CCGCG', '*****', '*****', 'CGCTC'); my $fseq4 = 'CCCCGCGC'; my @nsub4 = ('CCCCG', '*****', 'CGCGC'); #### $result4 = [ [ 0,'CCG--'], [ 1,'*****'], [ 2,'--CTC'] ]; $result5 = [ [ 0,'CCG--'], [ 1,'*****'], [ 2,'*****'], [ 3,'--CTC'] ]; $result6 = [ [ 0,'CCG--'], [ 1,'*****'], [ 2,'--CTC'] [ 3,'*****'], ]; #### my $count; my @ar; foreach (@nsub) { $c++ if ($_ =~ /[ATCG]/); next if ($_ =~ /^\*/); push @ar, $_; last if ($count == 2); } my $sec_str= $ar[$#ar]; #Second non-* strings print "$llm\n"; my @results; my %seen; my $previous = $nsub[0]; my $tmp = $previous; my ($found) = "$nsub[0]#$sec_str" =~ /(\w+)#\1/; if ($found) { $tmp =~ s/$found$/"-" x length($found)/e; } push @results, [ 0, $tmp ]; for (1 .. $#nsub) { my $current = $nsub[$_]; if ($current =~ /^\*/) { push @results, [ $_, $current] unless $seen{$_}++; } elsif ( "$previous#$current" =~ /(\w+)#\1/ ) { my $found = $1; (my $tmp = $current) =~ s/^$found/"-" x length($found)/e; push @results, [ $_, $tmp]; $previous = $current; } else { push @results, [$_,$previous]; push @results, [$_+1,$current]; #printf "%d -> no overlap\n", $_; $previous = $current; } } print Data::Dumper->Dump([ \@results], ['result']);