# Note we assign the return value of the sub to $txt $txt = escape_html_character($txt); sub escape_html_characters { my $string = shift; $string =~ s/...some chars here.../...some escape.../g; # Note we return the modified string return $string; }