The single quotes in this line should be removed. Currently the quoting allows the shell to parse Substr and you do not want that to happen.
Also the command is substr not Substr.
print " <td>"'{Substr($1,1,1)}' "</td>" ###### Line 17
change to-:
print " <td>" substr($1,1,1) "</td>"