#! usr/bin/perl $sentence = " he PP study VB A~~~language~A NP and CC play VB A~~~game~A NP ." $_ = $sentence; while ($_ ne '') { if (m/A~~~(.*)~A/g) { # global match $remainPart = $sentence; ($_) = /(\G(.|\n)*)/g; # store rest of the string # (after pos) to $_ $remainPart =~ s/$_//; print "$remainPart\n"; } else { $_ = ''; } }