my @a=qw(a b c d e f); my @b=qw(a b c); sub head_eq(\@\@) { my ($long, $short) = @_; @$short == 0 or (@$long and shift @$long eq shift @$short and &head_eq) } print "Equal!\n" if head_eq(@a, @b);