NSA in Perl

source

sub match
{
  my $index;
  my @word = @{$_[0]};
  my $state = $_[1];
  foreach my $c (@word)
  {
    $index++;
    if($state->{$c} eq 'end')
    { return "success"; }
    elsif(exists $state->{$c})
    {
      foreach $path (@{$state->{$c}})
      {
        my @rest = @word[$index .. @word];
        if(match(\@rest, $path) eq "success")
        {return "success";}
      }
    }
    else { return "failed"; }
  }
}