in reply to Matching and replacing

You can use word-boundary anchors like this...
$message_ref->[0] =~ s/\b$key\b/$method{$key}/;
Cheers.