#!/usr/bin/perl use strict; use warnings; # 847021 =head OUTPUT OF THIS VERS: >Long_DNA_Scaffold.0 atgctagsctgtagctagctagtcgatgctagtagct ttagctagctgatgctagtcgatgctagtcatctagc >Long_DNA_Scaffold.1 tagctagctagctgatcgtagctagtcgtagctagct ggtcgatgctgatcgtagctgatgctagtcgatgcta > # removal of ">" and blank lines left as an exercise.... >Long_DNA_Scaffold2.0 atgctagsctgtagctagctagtcgatgctagtagct tagctagctgatcgtagctagctgatgctagctagtc >Long_DNA_Scaffold2.1 tagctagctagctgatgctagctagtcgatcgtagct ggctagtgctagtgctagctgatgctagtcgtagctg =cut my $file = "847021.txt"; open (IN, '<', $file) or die "Can't open $file: $!"; # test your file opens! $/=">"; my $i=0; my $separator_count=0; my (@seq, $seq, @name, $name); while () { if(/^(\S+)?.*?\n(.*)/ms) { # $i++; # this creates an empty ("undef") element 0 in the arrays; mis-located; moved $seq[$i]=$2; $name[$i]=$1; } else { $separator_count++; if ($separator_count > 1) { print "No match for current data: $_\n\n"; # one instance is expected because the data begins with record separator; don't show it } else { next; # create no undef $arr[0] } } $i++; # re-located from line 57 } close IN; print "\n"; for my $j(0..$#seq) { # $#seq: index of last element. 0..$i replacing OP's 1..$i $name[$j] =~ tr/>//; # replaces OP's mis-coded tr//; see toolic's reply, above re tr syntax $seq[$j] =~ tr/>//; my @sequence=split(/N+/,$seq[$j]); my $n=length(@sequence); my$seqs_to_print=$n; # OP's decrement caused failure to print second elements of @seq for my $k(0..$seqs_to_print){ # use $i, $j, $k for counters; $x and company are typically for substantive data print ">$name[$j].$k\n"; print "$sequence[$k]\n"; } $j++; }