in reply to renaming files...

I'm not sure that you can use this but instead of writing your own script you could use rename like follows.
rename 's/-AM$//' *
In the directory that you need to rename the files. I believe rename is part of perl. HTH