You only print lines to your output file when they contain no whitespace.

if( /^(\S+)$/) {print OFILE"$1\n\n"}

From your input that may not be what you want. Are you after the first contiguous sequence on each line AFTER the first text with the scaffold<num> or just the entire line with the first part altered?

It would also be good practice to explicitly close your files when you are finished reading/writing them.

Update

# this may help while (my $line = <FILE>) { # The entire line with a substitution # if( $line =~ s/^>\S+\/>contig_$count) { # Substitution and 1st contiguous sequence if( $line =~ s/^>\S+\s+(\S+)/>contig_$count $1\n/) { print OFILE $line; $count++; } } close FILE; close OFILE;

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

In reply to Re: Renaming headers works for some files but fails for some files by Random_Walk
in thread Renaming headers works for some files but fails for some files by MVRS

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.