in reply to replace text using hash

Just had a similar problem.

First you need to sort the keys descending by length.

Then you need to build an "or'ed" pattern of those keys.

Like this the longest match has priority.

Something like:

$pattern = join "|", @sorted; $text =~ s/($pattern)/$hash{$1}/g;

Untested typing into my mobile :)

update

Your code has some issues, first you push the tgt (?) into a HoA

Then you are translating line by line, which won't catch expressions spanning line breaks.

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)