$sentence = " he PP study VB A~~~language~A NP and CC play VB A~~~game~A NP ."; $_ = $sentence; while (m/(A~~~([^~]+)~A)/g) { # debug print print $1 . "\t" . $2 . "\n"; # Remove our match push @parts, $2; $_ =~ s/$1//g; } $sentence = $_; # print the bits we took out foreach (@parts) { print $_ . "\n"; } # print the new sentence print $sentence . "\n"; #### $sentence = "A~~~one~A and A~~~two~A"; $sentence =~ m/A~~~(.*)~A/g; print $1;