use warnings; use strict; use File::stat; use Fcntl qw/S_IMODE/; my $filename = $0; # just for testing my $stat = stat($filename) or die "stat $filename: $!"; my $perms = S_IMODE($stat->mode); printf "%#0o\n", $perms; chmod $perms, $filename or die "chmod $filename: $!";