#!/usr/bin/perl use warnings; use strict; my $sfile_1 = "f0.txt"; my $sfile_2 = "f1.txt"; my ($id1, $seq1) = read_fasta($sfile_1); my ($id2, $seq2) = read_fasta($sfile_2); my $colno = 12; pretty_print($seq1, $colno); pretty_print($seq2, $colno); sub read_fasta { ## reads a single sequence from a fasta file my $seqFile = shift @_; my $seq = ""; my $id = ""; open(my $in, "<", $seqFile) or die "unable to open $seqFile $!\n"; while(<$in>){ chomp; if($_ =~ /^>(\S+)/ ){ last if(length($id)); $id = $1; next; } if(length($id)){ $seq .= $_; } } return ($id, $seq); } sub pretty_print { my($seq, $colno) = @_; # We want to start from 0, and increment the starting position. # for this we use a classical loop. for (my $b=0; $b < length($seq); $b += $colno){ print( substr($seq, $b, $colno), "\n"); } } exit;