Why don't you use
$ialchan? Then loop through the matches.
Using $ialchan(*!*@*,$chan,0).nick for example:
On *:Ban:#: {
var %x = 1
while (%x <= $ialchan($banmask,$chan,0)) {
echo -a $ialchan($banmask,$chan,%x).nick
inc %x
}
}
Just change the echo bit to how you stored the nicknames before.