in reply to Bug in code
just a suggestion, use an en passant modification of your input, like chomp($input = <STDIN>);