$_ = "-r-x-w-rwx"; # Mode string in $_ my $bits = 0; for (split //) { $bits *= 2; $_ ne "-" and $bits++; } printf "My bits are: %o\n", $bits;