in reply to Regex in if statemetn

Just in case you copied this snippet directly from your script, I wanted to let you know that in one place you are using $input[$an] and everywhere else using $input[an] (Note $an vs an)