If you think about this being a state machine and you don't use CPAN code, you're (probably) reinventing the wheel. The standard distribution for handling state machines in Perl is POE*.
But it's big and clunky and doesn't read like normal Perl code. For a simple FSM, there is absolutely no reason to use POE, as POE tends to make your app into a "POE application", transmogrifing it. Reinventing your own will result in something a lot more concise. POE is cool, but it is *much* more than just a state machine, and I really doubt everytime someone recommends it that they have actually used it for that purpose. Implementation of basic state machines WITHOUT goto's is basic CS1, and those that use goto's to do this are doing really shoddy programming.
Gotos (and their P.C. cousins "abused exceptions") must die. They lead to poorly maintainable code that is both hard to read and trace.
A simple state machine without gotos (pardon the syntax errors):
$state = 'foo';
$running = 1;
while($running) {
if ($state eq 'foo') {
# do stuff
$nextstate = 'bar';
}
elsif ($state eq 'bar') {
# do stuff
$nextstate = 'baz';
}
elsif ($state eq 'baz') {
# do stuff
$running = 0;
}
$state = $nextstate;
}