Perl fork

Hi, I want to exec three different functions in perl one per fork();
How can I determine that this it the third fork and I should use third function in it.

if ($pid = 0) { first();}
else (
#parent
second();
)

How to run third function?

Option 1: fork twice (pseudocode)

fork()
  if child: first()
fork again()
  if child: second()
third();

Option 2: remember how many forks you've done in an array (no guarantee on correctness):

@a=();
while(scalar @a < 3){
    $pid=fork();
    push @a,$pid;
    first() if $pid==0 && scalar @a==1;
    second() if $pid==0 && scalar @a==2;
    third() if $pid==0 && scalar @a==3;
}

Personally, I think the first one is better in terms of readability.