use strict; use warnings; my $string = 'insertreallylongstringwithlotsandlotsoffunkycharactersandifonefeelsreallyspecialperhapsevenaspacesomewhere"; 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++; }