DSA in Perl

source

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