I assumed the line breaks in the data was unintentional and that each line began with >:
(timtowtdi)
use strict; use warnings; while (<DATA>) { chomp; my @parts = split /\s+/,$_; ## $parts[0] = substr $parts[0],1,-1; $parts[1] = $1 if $parts[1] =~ /length=(\d+)/; print join(",",@parts),"\n"; } __DATA__ >G9JVYGV01AJE8V length=135 xy=0104_0349 region=1 run=R_2011_09_20_15_0 +0_06_GGTGGTAGTGAAGAAGAGGAGATGAAAGTGGAAGAGGTTGAGGATGAGAAGGTTGAATTGGAAG +AAGAAGATGAGAAGGTTGAAGTGGAAGATGAGAAGGTTGAAGTGGAAGAAGATGAAGTGGAAGAGAGGA +GC >G9JVYGV01A4910 length=90 xy=0353_0150 region=1 run=R_2011_09_20_15_00 +_06_GGTGCATGGCATTGTAGATGGTTGCTTGATAGTTGCCCATACGTGTACTACACTTGCAGAGTGAA +GCAACCATCTACAATGCCATGCACC >G9JVYGV01A0SVP length=70 xy=0302_0163 region=1 run=R_2011_09_20_15_00 +_06_GCACCATTCAGCACAGATATAGTAGCCACATCAACACAAGTTACCTAACTATATCTGTGCTGAAT +GGTGC >G9JVYGV01A221U length=89 xy=0328_0160 region=1 run=R_2011_09_20_15_00 +_06_CTGGACATTTACATCCATAAGTAGGAGTTAGGACTCTGCACCAGCCTCTTGAGCTTGTGACGTCT +CTTCTCCTCCTCCGGACTGGGACA >G9JVYGV01BVCPK length=46 xy=0650_0134 region=1 run=R_2011_09_20_15_00 +_06_GCAAGATCGCAAGCCAAGCAACGTTTCACGAACTGGCCAGAATGAG >G9JVYGV01AOU3I length=81 xy=0166_0220 region=1 run=R_2011_09_20_15_00 +_06_TCATTGACATCTGTGCAGCTGCAGGAGCGGATATGAGGAGATGGTTCTATCTGCACAGATGTCAA +TGAGTGTGACAGTGAT >G9JVYGV01A0JEL length=61 xy=0299_0171 region=1 run=R_2011_09_20_15_00 +_06_CGAGTGAAGGCATTGGTGATGCTGGTGTGAAGAGTGAGGGCATCGCCAATGCCTTCACTCG

I like using split instead as it's a little less fragile when it comes to parsing input. Edit: I guess the OP wanted to preserve the ">" at lines' beginning, which I didn't.

mr.nick ...


In reply to Re: Perl script help to convert .txt file to .csv by mr.nick
in thread Perl script help to convert .txt file to .csv by Seabass

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.