#!/usr/bin/perl use warnings; use strict; my $infile=$ARGV[0]; my $header; my %sequence=(); open FASTA, $infile or die "Couldn't open fasta-file"; open (OUTFILE,">fasta_report.txt"); # Populate a hash with the fasta-data # fasta example: #>fasta1 #NNNAGTCTGCAAANAATTTGCGGCTCACAAT #>fasta2 #CGCAGCCATTAACATCTCAACAAGCCAAAAATTCCTTCTCAGAAATTCGGNNN while () { chomp; if (/^>(.*)$/){ $header=$1; } elsif (/^(\S+)$/){ $sequence{$header} .= $1 if $header; } } close FASTA; #Go through the hash and split at Ns foreach my $key (keys %sequence){ my @contigs = split (/N+/, $sequence{$key}); foreach my $element (@contigs){ print OUTFILE "$element\n"; } } close OUTFILE;