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