ref atgtagctagctagctaacgagcgctagctagctagtgatg substr agctagctagctaac #### $reference_string = 'gctagctgatgctagcagcagcatgtagctagctgacga' $substring = 'aatgctagctagc' $output_line = qw{ } x length($reference_string); substr $output_line, $start_position, $length, $substring; print $reference_string, "\n", $output_line; #### ref agctagctagctagcatgctagctagctgatcgatgctagctagctgactgacgacg out1 atctagcat agctagcgatcga gactgacagc out2 tagctagctgctagc out3 agtcgatcgatgctagc #### create one blank line of output foreach substring take the first blank line if there is no overlap substr the blank line if there is overlap create a new blank line substr the new blank line