open(FILE,"test.txt"); while(){ if(/^sample\s+(\S+)/){push @sample,$1} if(/^good\s+(\S+)/){push @good,$1} } close(FILE);