use strict;
use warnings;
#store params from file1
my (%params);
open(my $FILE1, "< file1.txt") or die $!;
my @arr = <$FILE1>;
foreach(@arr){
#extract key-value pairs \s* = any number of spaces, .* = anything
#\w+ = any sequence of letters (at least one)
my ($key, $value) = ($_ =~ /(\w+)\s*:\s*(.*)/);
$params{$key}=$value;
}
close $FILE1;
open(my $FILE2, "< file2.txt") or die $!;
my @arr2 = <$FILE2>;
foreach(@arr2){
my ($key, $value) = ($_ =~ /(\w+)\s*:\s*(.*)/);
#if the found key did exist in params, then replace the found value, with
#the value from file 1 (this may be dangerous if value contains regexp chars,
#consider using e.g. \Q...\E
if (exists $params{$key}) {
#replace the row in @arr2 inline using direct ref $_
$_ =~ s/$value/$params{$key}/;
}
}
close $FILE2
#replace / output the result /here to a different file, not to destroy
open(my $FILE2W, "> file2_adjusted.txt") or die $!;
print $FILE2W @arr2;
close $FILE2W