in reply to stat and permissions

store them in a scalar in binary. e.g. "0755"
I just want to store those 4 numbers in a scalar.

sprintf returns a string, and the "4 numbers" includes a leading zero which is just decoration indicating that the number is octal (base 8). Converting that string into a numeric will only remove the leading zero. If you want the value as an integer (which I assume is what you mean by 'binary') then ignore the printf or sprintf:
use warnings; use strict; use Devel::Peek; my $file = $0; my $mode = sprintf '%04o', (stat $file)[2] & 07777; print "sprintf Permissions are $mode\n"; print "\twhich is ",oct($mode)," in decimal\n"; print Dump(\$mode),"\n\n"; my $n_mode = (stat $file)[2] & 07777; print "stat Permissions are $n_mode decimal\n"; print Dump(\$n_mode),"\n";
In the output the string scalar $mode is "0666" but the integer scalar "$n_mode is 438:
sprintf Permissions are 0666 which is 438 in decimal SV = RV(0x3a1b8) at 0x3a1ac REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x18abfd4 SV = PV(0x3807c) at 0x18abfd4 REFCNT = 2 FLAGS = (PADMY,POK,pPOK) PV = 0x18b1614 "0666"\0 CUR = 4 LEN = 8 stat Permissions are 438 decimal SV = RV(0x3a1b8) at 0x3a1ac REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x18bada4 SV = PVIV(0x18a0f4c) at 0x18bada4 REFCNT = 2 FLAGS = (PADMY,IOK,POK,pIOK,pPOK) IV = 438 PV = 0x18a1f2c "438"\0 CUR = 3 LEN = 4
You can see that $mode does not have an integer value (IV) at that point, only a string value (PV).