Just one question...where did you initialize $_?
Or shouldn't the places where you do $_->[$p] be $_[0][$p]
unless you have an invisible ($_)=@_; at the beginning?
Interesting algorithm, I'm sure I would be useful for something...someday, I just can't think what :)