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