my $is_break = 0; $SIG{INT} = sub { $is_break = 1 }; my $result = is_success( getstore( $uri, $localfile ) ); if($is_break) { print STDERR 'Removing incomplete download...'; -f $localfile and ( unlink $localfile or print STDERR "\rCouldn't remove incompletely downloaded $localfile: $!\n" ); } exit $result;