#!/usr/bin/perl use strict; use warnings; my $ifh = open("<:raw", "./file-bar.png"); my $data = unpack('a*', $ifh); my $outputfile = "newfile.png"; open (my $ofh, '>:raw', $outputfile) or die "Could not open '$outputfile' $!"; print $ofh pack('a*', $data); close $ofh; print("Image created.\n");