#!/usr/bin/perl
$s =  {a => {b => {c => 'end'}}};
@w = (a,b,c,d,e,f);
$w = \@w;

print match($w,$s), "\n";

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

