open (PROG, "+>>$0"); #### #!/usr/bin/perl use strict; use warnings; my $new_value = 10; my $data=45; open (PROG, "+>>$0"); seek (PROG, 0, 0); #not working while () { s/^(my .data\s*=\s*)\d+(\s*;)/$1.$new_value.$2/e; print; } close (PROG); #### #!/usr/bin/perl use strict; use warnings; my $new_value = 10; my $data=10; open (PROG, "+>>$0"); seek (PROG, 0, 0); #not working while () { s/^(my .data\s*=\s*)\d+(\s*;)/$1.$new_value.$2/e; print; } close (PROG);