my $u = $<; setuid(0) || die "Cannot change UID from $u to 0"; system(split(' ','/sbin/modprobe usb-storage')); setuid($u) || die "Cannot drop privileges"; system(split(' ','/sbin/mount /mnt/usb/flash')); [do some file manipulation in here] chdir ('/'); system(split(' ','/sbin/umount /mnt/usb/flash')); sleep (2); # this is pure raging paranoia setuid(0) || die "Cannot change UID from $u to 0"; system(split(' ','/sbin/modprobe -r usb-storage')); setuid($u) || die "Cannot drop privileges";