#!/usr/bin/perl -T -- use strict; use warnings; use CGI qw(:standard); print header, start_html('Upload example'); print_form() unless param; print_results() if param; print end_html; sub print_form { print h2('What file do you have for me?'), start_multipart_form(), filefield(-name => 'upload', -size=>60), submit(-label => 'Do it!'), end_form; } sub print_results { my $output_file = '../whatever'; my $file = upload('upload'); print h2('Bummer!...') and return unless $file and open my $out, ">$output_file"; { my $data; print $out $data while read $file, $data, 1024; } close $out or print h2('Not all is well...') and return; print h1('Success!'); }