my $string = ""; my @new_array; for my $item (@contigfile) { if ( $item =~ /^>\d) { push @new_array, $string unless $string eq ""; $string = ""; } else { $string .= $item; } } push @new_array, $string; # takes care of the last element #### my $string = ""; while (my $line = <$input_fh>) { chomp $line; if ( $line =~ /^>\d) { push @new_array, $string unless $string eq "";; $string = ""; } else { $string .= $line; } } push @new_array, $string; # take care of the last element