use Text::Quote::Self qw(quote_text); my $safe = quote_text($user_input); # create a magic string object $safe = Text::Quote::Self->new($user_input); # ditto say $safe; # input as is say $safe->as_uri; # uri-encoded $safe =~ s/foo/bar/; # changes original, permanently my $data = { text => $safe }; # elsewhere in the app say JSON::XS->new->allow_blessed->convert_blessed->encode($data); #text as is local $Text::Quote::Self::Style = "as_html"; say $data->{text}; # now with entities # or in a Template You were searching for [% search_term %].