use Term::ReadKey; sub masked_read(;\$$) { my $mask; if($_[1]){ if(length $_[1] > 1){ die "arg 2 of masked_read() should only be 1 character long"; } $mask = $_[1]; } else{ $mask="*"; } my $key; $|=1; while(1) { while(not defined($key = ReadKey(-1))) {}; if(ord($key) != 13) { if(ord($key) == 8) { print "\b \b"; chop(${$_[0]}); } else { ${$_[0]} .= $key; print "$mask"; } } else {last} } $|=0; return ${$_[0]}; } print "Enter:"; my $password = masked_read; print "\npassword:$password"; #### masked_read($password, $mask); masked_read($password, '#'); masked_read($password); my $password = masked_read();