my %data = ( foo => 'oof', bar => 'rab', ); my $text = "foo/bar"; $text =~ s/(\w+)/$data{$1}/g; print "($text)\n";