#!/usr/bin/perl use warnings; use strict; my $input = "471234973798375754773971832374974447889743725345932"; my $pos = 0; while (-1 != ($pos = index $input, '47', $pos)) { print substr($input, $pos++, 10), "\n"; }