use POSIX qw(floor); sub dec2Bin($) { $n = shift; while ($n != 0) { $k = $n % 2; $n = floor($n / 2); $b = $k . $b; } print "$b"; }