$string="He0Hello~~He2World~~"; while ($string=~m/He\d(\w+)~~/g) { print "$1\n"; }