#!/usr/bin/perl use warnings; use strict; my $input = 'rnbqkbnr'; my $search = 'n'; my @positions; my $pos = 0; while ($pos = 1 + index $input, $search, $pos) { push @positions, $pos - 1; } print "@positions\n";