#!/usr/bin/perl use strict; use warnings; my $str = 'The %NOUN% can jump very %ADVERB% with his %APPENDAGES%'; my %wb = ( NOUN => "kangaroo", ADVERB => "far", ); $str =~ s/%([^%]+)%/$wb{$1} || "\%$1\%"/ge; print "$str\n";