use warnings; my @lines; my $mess; open(hanr,"splitin.pl")or die"error $!\n"; open hanw, ">", "output.csv" or die $!; @lines = ; foreach my $line (@lines) { chomp($line); $line =~ /^\$outcome /x or next; my $Length = -2; my $mess = substr $line , 10 ,$Length; print hanw "$mess , \n"; } close hanr; close hanw;