my %sub = { ">" => "\t\t++k;\n", "+" => "\t\t++*k;\n", ... # fill as needed } #### s/(.)/$sub{$1}/ge