Q:

Find and replace a string in a text file in perl

I really have no idea how to do this I tried a lot methods and I don't know why none works.Here is a sample of what I tried ...
{
    open my $fh1, '<', 'hex1.txt';
    open my $fh2, '<', 'hex2.txt';

    until ( eof $fh1 or eof $fh2 ) {

        my @l1 = map hex, split //, <$fh1>;
        my @l2 = map hex, split //, <$fh2>;

        my $n = @l2 > @l1 ? @l2 : @l1;

        my @sum = map {
            no warnings 'uninitialized';
            $l1[$_] + $l2[$_];
        } 0 .. $n - 1;

        @sum = map { sprintf '%X', $_ } @sum;

        open my $out, '>', 'hexsum.txt';
        print {$out} @sum, "\n";
    }
    close $fh1;
    close $fh2;
}

{

    open my $IN,  "<", 'hexsum.txt';
    open my $OUT, ">", 'sym.txt';
    while ( my $linie = <$IN> ) {
        $linie =~ s/40/20/g;
        print $OUT $linie;
    }
    close $IN;
    close $OUT;
}

{
    my $input = do {
        open my $in, '<', 'hexsumspace.txt';
        local $/;
        <$in>;
    };

    open my $out, '>', 'sym.txt';
    print $out pack 'H*', $input;
}

I want to change everywhere I find the value 40 with the value 20...

A:

use strict;
use warnings;

open my $OUT, ">", 'output.txt';
open my $IN, "<", 'input.txt';
while (my $line = <$IN>) {
    $line =~ s/40/20/g;
    print $OUT $line;
}
close $IN;
close $OUT;

A:

Here's a perl one liner from the commandline:
perl -pe 's/40/20/g' input.txt > output.txt

