#set some local variables local ($name,$toys); open ( INPUT , ") { @name=split(" ",$_) if /^-- NAME:\s(\w+)/; @toys=split(" ",$_) if /^-- TOYS:\s(\w+)/; } close(INPUT); foreach $name (@name) { print "the name $name\n"; } foreach $toys (@toys) { print "the toys $toys\n"; }