in reply to Problem in printing lastname and firstname

You are using split('',$input) which splits $input into individual characters. You should be using split(' ',$input) which will split on whitespace.