while () { my ($group,$x,$gid,$list)=split(':',$_); push(@groups,$group) if ($list=~/$username/); }