in reply to Producing a list of offsets efficiently

use strict; use warnings; my $string = 'insertreallylongstringwithlotsandlotsoffunkycharactersan +difonefeelsreallyspecialperhapsevenaspacesomewhere"; my $char_to_be_matched = 'X'; my @matches; my $offset = 0; foreach my $char (split(//, $string)) { if($char eq $char_to_be_matched) #alternatively some regex magic { push(@matches, $offset); } $offset++; }
I'm pretty certain there's one or more things that I'm not taking into account in this example, but you get the general idea ;-)


Remember rule one...