#!/usr/bin/perl use warnings; use strict; my @contigfile = qw( >37 ABC DEF GHI >456 JKL MNO PQR STU VWX YZ >38 ); my @result; for my $i (0 .. $#contigfile) { my $current = $contigfile[$i]; push @result, q() and next if 0 == index $current, '>'; $result[-1] .= $current; } print "$_\n" for @result;