open(DATA, "s5378_scan.v") or die "error: $!"; while () { if ($_ =~ /input/) { $length_line = length ($_); $x= $length_line - 7; $portion = substr($_, 7, $x); } my $str = $portion; my $find = ","; my $replace = ";"; $find = quotemeta $find; $str =~ s/$find/$replace/g; open (MYFILE, '>data.txt'); print MYFILE "$str\n"; close (MYFILE); } # End while close(DATA)