in reply to formatting output question (use of recursive subroutine?)

Hi, this comes close to your suggestion, but it tries to find a match in the lines created before. Don't know if it fits your requirements (see comments). And it can surely be optimised...
use strict; use warnings; my $ref = 'agctagctagctagacatgctagctagctgatcgatgctagctagctgactga +cgacgacat'; my @fragments = qw(agc tagcg agca atgctagctagc acga gcatgc acat tagctg +atcgatgct); my @out; my @nomatch; # what it does *not*: # a) show each occurence of a fragment, e.g. 'acat' # b) separate adjacent fragment, e.g. agc and tagcg will be # seen as agctagcg # c) optimising (minimum number of lines) # d) check that a fragment is a fragment of another fragment # (e.g. "agc" is part of serveral other fragments) outer: foreach my $fragm (@fragments) { my $pos = index($ref,$fragm); push (@nomatch, $fragm), next if ($pos<0); # no match my $len = length($fragm); foreach (@out) { if (substr($_,$pos,$len) =~ /^\s+$/) { # found first empty slot substr($_,$pos,$len) = $fragm; next outer; # done, try next fragm. } } # could not fit fragment -> add it as a new line push @out, ' ' x length($ref); substr($out[-1],$pos,$len) = $fragm; } # and out print "ref: $ref\n"; print "out: ", join("\nout: ", @out), "\n"; print "no match: ", join(", ", @nomatch),"\n";