in reply to my script is not giving the result using last function
You forgot to chomp
Also, you forgot to rindex instead of substr :)