while ( $txt =~ /$srch/g ) { push @offset, pos($txt) - 1; } #### push @offset, pos($txt) - 1 while $txt =~ /$srch/g; # while ( $txt =~ /$srch/g ) { push @offset, pos($txt) - 1 }