in reply to Expect module & su

This probably isn't your actual problem, but it is a flakey waiting to happen, in that metacharacters in your arguments may make the substituitions do more than you expect. This:
if($#ARGV > 2) { $message = join (" ",@ARGV); $message =~ s/$username//; $message =~ s/$password//; $message =~ s/$on_off//; }
would be better as:
if($#ARGV >2 ) { $message = join (" ",@ARGV[3..$#ARGV]); }
Either that or use e.g. quotemeta($password) in the first part of your substitutions.

--Bob Niederman, http://bob-n.com