This very trivial piece of code was not obviously found, so now I've worked it out, I thought I'd dump it here.

Read a file's permission settings.

Update: originally omitted end of sprintf statement - oops...

my $mode = (stat("/file/path"))[2]; my $permissions = sprintf("%04o",$mode & 07777); # where $permissions is an octal string, eg "0755", "0644" # update - tye suggests this instead: my $timtowtdi_permissions = sprintf("0%03o",$mode & 0777);