my @grid = ( [ split( //, 'ABPR' ) ], [ split( //, 'CAEL' ) ], [ split( //, 'TSRX' ) ], [ split( //, 'OILW' ) ] ); my $h = 4; my $w = 4; sub find { ... } my @results = find( \@grid, $w, $h, "PERL" ); # # @results can be: # ( 2, 0, 4 ) if using 1-8 numbers # ( 2, 0, 0, 1 ) if using direction # ( 2, 0, 2, 3 ) if using end point my @results = find( \@grid, $w, $h, "GOLD" ); # @results = ()