my @matches = grep /\Q$search\E/i, @array; if (@matches > 12) { print @matches-12, " matches ignored\n"; $#matches = 11; } while (my @row = splice(@matches, 0, 3)) { print "