use strict; use warnings; use feature 'say'; use LWP::UserAgent; my $foo = 'bar'; $SIG{'INT'} = sub { $foo = 'baz'; }; my $ua = LWP::UserAgent->new; $ua->add_handler("response_data", sub { if ( $foo eq 'baz' ) { say 'killing UA now'; croak(); } return 1; }); my $url = 'http://ipv4.download.thinkbroadband.com/10MB.zip'; my $filename = "$0.zip"; my $forked = fork // die 'Could not fork!'; if ( $forked == 0 ) { # child say "In child with $$"; my $req = HTTP::Request->new( GET => $url ); my $res = $ua->request( $req, $filename ); exit; } my $done = wait; say "In parent: $done done"; exit;