use File::Copy;
umask 022 or die "Failed to set umask: $!";
copy $src => $dest or die "Failed to copy: $!";
####
system cp => '-a', $src, $dest;
die "..." if $?;
####
#!/usr/bin/perl
use strict;
use warnings;
use File::Copy;
umask 022 or die "umask: $!";
my $one = "/tmp/one";
my $two = "/tmp/two";
my $three = "/tmp/three";
foreach my $file ($one, $two, $three) {
! -f $file or unlink $file or die "unlink $file: $!"
}
# Create first file.
open my $fh, "> $one" or die "one: $!";
close $fh;
# Make it executable.
chmod 0755 => $one or die "chmod: $!";
# Copy it with File::Copy.
copy $one, $two or die "copy: $!";
# Copy using the UNIX toolkit.
system cp => $one, $three;
die "cp: ", $? >> 8 if $?;
# And check.
print "$one is executable\n" if -x $one;
print "$two is executable\n" if -x $two;
print "$three is executable\n" if -x $three;
__END__
/tmp/one is executable
/tmp/three is executable