use strict; use warnings; use Data::Dumper; my @pos; my $str = "foobarbaz"; if ($str =~ s{([aeiou]+)(?{ push @pos, pos $str })}{<--$1-->}g){ print Dumper \@pos; print $str, "\n"; }