# process the input and be done with it... die"error $!\n" unless open hanr,"splitin.pl"; my @lines = ; close hanr; my $r = ''; # its easier to debug when you have a scalar you can print later, rather than printing line by line... for my $line ( @lines ) { # odd since $outcome is undef .. ? next unless $line =~ /^\$outcome /x; $line =~ s/.{9,9}(.+)../$1/; # get the middle chars $r .= $line; #append # print hanw "$mess , \n" # why chomp then add \n back in? Just leave it there....; } # process the output here die $! unless open hanw, ">output.csv"; print hanw $r; close hanw;