foreach (@tcpstatus) { while (/\b01\s/) { push(@tcpalive,$_); last; } } #### @tcpalive = grep { /\b01\s/ } @tcpstatus;