Assuming that there will be more than one line of data to process, I wrote the following:
use strict; { local $/ = 'output'; while (<DATA>) { chomp; # drop 'output' my (undef, $line) = split /input/; $line =~s/,/;/g; print "$line\n"; } } __DATA__ input CK, n3065gat, n3066gat, n3067gat, n3068gat, n3069gat, n3070gat,n +3100gat, test_si, test_se; output n3104gat, n3105gat, n3106gat, n3107gat, n3108gat, n3109gat, n +3110gat; input CK, n3065gat_2, n3066gat_2, n3067gat_2, n3068gat_2, n3069gat_2, +n3070gat_2,n3100gat_2, test_si, test_se; output n3104gat_2, n3105gat_2, n3106gat_2, n3107gat_2, n3108gat_2, n +3109gat_2, n3110gat_2; input CK, n3065gat_3, n3066gat_3, n3067gat_3, n3068gat_3, n3069gat_3, +n3070gat_3,n3100gat_3, test_si, test_se; output n3104gat_3, n3105gat_3, n3106gat_3, n3107gat_3, n3108gat_3, n +3109gat_3, n3110gat_3; input CK, n3065gat_4, n3066gat_4, n3067gat_4, n3068gat_4, n3069gat_4, +n3070gat_4,n3100gat_4, test_si, test_se; output n3104gat_4, n3105gat_4, n3106gat_4, n3107gat_4, n3108gat_4, n +3109gat_4, n3110gat_4;
It works by setting the input record separator '$/' to 'output', so every line you read will be terminated by 'output', rather than by the usual EOL.

chomp removes the 'output'.

Then I split the line just read on 'input' and throw away everything before 'input', leaving me with nothing but what is between 'input' and 'output'. The substitution s/,/;/g takes care of changing commas into semi-colons. There is no need to quotemeta them as they are not special in a regex. The result then gets printed.

BTW: you are opening, printing and closing the file for every line. Not only is this very slow, it is also wrong as each opening of the file for output with '>' will delete everything which was in that file, so you end up with only the result of your last print. Keep your open and close outside of the loop.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Update: fixed typo.

In reply to Re: writing all the strings between two particular substrings by CountZero
in thread writing all the strings between two particular substrings by giridharreddy9

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.