After changing it to while(my $r=$sth->fetchall_hashref;) what does the following line denotes: for my $r (@$table) { my $name='other'; for my $s (@sys){ if ($r->{queue_name}=~m/$s/i) {$name=$s; last;} }