Thanks all of you for your replies. Please find the following code.If you have any further changes to this code please let me know .Also, I don't know how to use text::csv , so if anyone could help, it will be nice.

#!usr/bin/perl use strict; open FH, "/home/test1/hello.csv" or die; my @array,@array1; #----------I'm pushing all abc's and def's data into respective arrays +--------------------------- while(<FH>) { if ($_=~/^abc/) { push(@array,$_); } elsif($_=~/^def/) { push(@array1,$_); } } #----------I'm writing only one for loop for abc, it will be same for +def too. ------------------------------ my @hello; foreach my $i(0..$#array-1) { #-------below code: it splits the second abc and and so on. i.e., stri +ps second abc from the digits.------------------- @hello=split /^\w+\,/,$array[$i+1]; foreach my $j(0..$#hello) { #--------below code:this is for replacing \n of first abc,2,3,4,5,6 wi +th a comma ( ex: abc,2,3,4,5,6, ) $array[$i]=~s/\n/,/g; #--------------below code:here it concatenates the data ( data should +look like: 2,3,4,5,6,7,5,2,1,6,2,3,8,2,1,3,1,4 )---------- abc,$array[$i]=$array[$i].$hello[$j]; print $array[$i],"\n"; } } # In my above code, the data is concatenated as follows: abc,2,3,4,5,6 ,7,5,2,1,6,2,3 ,8,2,1,3,1,4 #But expected output is : abc,2,3,4,5,6,7,5,2,1,6,2,3,8,2,1,3,1,4

In reply to Re^2: Combining multiple lines based on the given condition by anony
in thread Combining multiple lines based on the given condition by anony

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.