open(FILE1,"e.txt")or die "can't open file for reading\n"; while () { chomp; next if(/^\s*$/); my $FastaLine= $_; if ( $FastaLine =~ /^>sp\|(\w+\S+)\|/ ) { $header = $FastaLine; } else #storing the sequences and appending the sequence lines that come after each header #and storing the sequence as values of $header { $Fasta_split{$header} .= $FastaLine; } if ( $header =~ /^>sp\|(\w+\S+)\|/ ) { my $name = $1; #print "$name\t"; } } while (($header,$Fasta_split{$header})=each(%Fasta_split ) ){ if ( $header =~ /^>sp\|(\w+\S+)\|/ ) { my $name = $1; #print "$name.txt\n"; #print"$name\n$Fasta_split{$header}\n"; my @words= split"", $Fasta_split{$header}; foreach my $w(@words){ $count{$w}++; } while (my($w,$c)=each(%count)){ print "$w:$c\t"; } print "\n"; } }