#!/usr/bin/perl -w use strict; my $string = "aXbcXdefgXhijXklmnopqrXstuvwXyz"; my $target = "X"; my $count = 0; my @indices = map{$count++;/$target/? $count-1:();}split //,$string; print "@indices"; exit