in reply to Renaming headers works for some files but fails for some files

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!