my $infile = "some file" my $outfile ="/the/path/to/the/file/$AdsID.jpg" open(IN, "<$infile") or die "Unable to open $infile for reading: Perl says $!"; open(OUT,">$outfile") or die "Unable to open $outfile for writing: Perl says $!"; binmode IN; binmode OUT; while (read(IN, $data, 16384)) { print OUT $data; } close OUT; close IN;