When the Read Mode file handler doesn’t to utilize another process you closed the file hander.
Then open the file a file handler in Write Mode with the same file name and print the contents you will the new (updated) contents in the sample file.
#!/usr/bin/perl
$fileName = "abc";
open(IN, "<", "$fileName") or die "Could not open file $fileName";
read IN, my $new, -s IN,
close (IN);
$new =~ s/foo/bar/g;
# Open the the file in write mode
open(OUT, ">", "$fileName") or die "Could not open file $fileName";
# print the new contents
print OUT $new;
close (OUT);