for(my $i=0;$i<50;$i++) { my $tmp = new File::Temp('DIR' => '/tmp', 'UNLINK' => 1); $SIG{INT} = sub { unlink "/tmp/".$tmp->filename; die }; ## <- add this line sleep(1); }