$str = "aa\nbb\ncc\naa\ndd\nee\n"; @a = ($str =~ /aa\n.*\n.*/g); print "1 = $a[0]\n2 = $a[1]\n";