use strict; use warnings; my $test = "fee fi fo free"; if ($test =~ m!((??{ print "$_\n";substr($test,0,$_) }))!) { };