$tmp = @ARGV[0]; $i = 0; while( 1 <= $tmp ) { $tmp /= 2; $i += 1; } print 2 ** $i; #### sub nextpow2 { my $s= shift(@_); my $p= 1; $p *= 2 while $p <= $s; return $p; }