in reply to clear STDIN
Presumably you shouldn't have to flush (clear) STDIN unless something else in your program is going wrong. You might be able to figure out where the extra input is coming from by printing out $message immediately after you read it. If that doesn't help, a hexdump might.
my $message = <STDIN>; print qq{\$message = "$message"\n}; printf "%02x ", ord for split //, $message; # hexdump
|
|---|