my $i=1; $i=~/(.)/; while ($i++<=4) { print "\$i = $i\n"; print "first: \$1 = $1\n"; $i=~/(3)/; print "second: \$1 = $1\n"; } print "after: \$1 = $1\n";