name Brian shirt yellow socks black device ipad 2001 device ipad 2001 device ipad 2001 tag no tag 0 name Andrew shirt orange socks black device ipad 2009 tag no tag 0 name ryan shirt blue socks black device ipad 2005 device cell 2009 tag yes tag 1 #### my @file = `cat text.txt`; foreach my $line (@file) { while $line =~ /name \s+(*.?) \s+(.*?)/mgx my $name = $1; }