while (my $match = '1 foo 22 bar 3' =~ /(\d+)/g) { print "$1 "; }