#! /usr/bin/perl -w use strict; my $r = qr{(.)}; while ('abc' =~ /($r)/g) { print "loop $1\n"; } foreach ('abc' =~ /($r)/g) { print "array $_\n"; }