#!/usr/bin/perl -w use strict; my $num = '123'; # an external database ID, for example warn "(PID $$) Beginning transaction #$num "; eval { my $pid = fork(); if ($pid) { warn "\t(PID $$) the parent does OK"; } else { eval { warn "\t(PID $$) the child fails"; die "\t(PID $$) Child process failure"; }; warn $@ if $@; exit; } }; if ($@) { warn "(PID $$) Rolling back transaction #$num: died in eval with $@"; } else { warn "(PID $$) Committing transaction #$num"; }