in reply to Replace value in the text file

#!/usr/bin/perl # http://perlmonks.org/?node_id=1193751 use strict; use warnings; use Path::Tiny; my %hash = map /^("\w+"),("\w+")/, path('file2.txt')->lines; my $pattern = do { local $" = '|'; qr/@{[ keys %hash ]}/ }; path('file1.txt')->edit_lines( sub { s/^($pattern).\K"\w+"/$hash{$1}/ +} );