my $gpg = '/home/gpghrp/.gnupg'; my $file = "$gpg/scripts/gpg_encr.saved"; my $temp = "$file.new"; open(OLD, '<', $file) or die "Can't open $file: $!\n"; open(NEW, '>', $temp) or die "Can't create $temp: $!\n"; while () { # Faster than regexp for plain text. if (index($_, '(?)readonly tlx=') >= 0) { substr($_, 13, 8, "blah"); } print NEW $_; } close(NEW); close(OLD); rename($temp, $file) or die "Can't update $file: $!\n"; #### perl -i -pe '/\Q(?)readonly tlx=\E/ && substr($_,13,8,"blah");' /home/gpghrp/.gnupg/scripts/gpg_encr.saved