# this may help while (my $line = ) { # 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;