Use /gc to remember position
#!/usr/bin/perl use warnings; use strict; my $text = "3 2 1 abc"; while ($text =~ /(\d)/gc) { print "$1...\n"; }