in reply to Re^3: Multiline Regex replacement in Multiline file
in thread Multiline Regex replacement in Multiline file

Hi Athanasius, the only solution i was looking for was to avoid loops, otherwise i am already doing it via looping through Keys and replacing matching string. I am not an expert but this is what i have been doing already :)

my $line=join "", <F>; foreach $k (keys %dic) { $line =~ s/$k/$dic{$k}/gism; } print $line;

Replies are listed 'Best First'.
Re^5: Multiline Regex replacement in Multiline file
by choroba (Cardinal) on Sep 17, 2014 at 11:47 UTC
    You can create a pattern that matches all the keys, and then replace:
    my $pattern = join '|', map quotemeta, keys %dic; $line =~ s/($pattern)/$dic{$1}/g;
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ