#Replace greetings value my $hash = sub { exists($hash{$2}) ? $hash{$2} : $1 }; $value =~s/(-(\S+?)-)/&$hash()/ge;