in reply to regex substitution

you can group your expression to use it later in your substitution statement: $text =~ s/\#(\w+)\#/$hash{$1}/g; $1 refer to the first grouped expression in your regexp, so variable_name there.