in reply to Substitution of text within a file

As you have noted, this does not change the file in place. You have two possible approaches here :

  1. Create a second file instead of personel.txt, and overwrite personel.txt at the end of your program
  2. Use the Tie::File module to treat your file as an array
The first approach will need almost no modification of your script and only the addition of the rename code to the end of your script. The second approach will need some modification of your script, but after that, your script will also run on a system that does not have grep installed. An example for how the second approach could look is :

#!/usr/bin/perl -w use strict; use Tie::File; my $newdigit="+615"; my $search_id="0001"; my $personel_filename; my @personel; tie @personel, 'Tie::File', File::Spec->catfile($FindBin::Bin,$persone +l_filename) or die "Couldn't read '$personel_filename'\n"; for my $line (@personel) { my ($id, $name, $family, $oldphone)=split(/\|/, $line); # Look if we want to replace the phone if ($id eq $search_id) { $newphone = $newdigit .$oldphone; # And overwrite the line in the array $line = join ("|",$id, $name, $family, $newphone); }; };