#!/usr/local/bin/perl use strict; use Data::Dumper; my $str = 'abacadabra'; my @matches; push @matches, [ map { substr $str, $-[$_], $+[$_]-$-[$_] } 1..$#+ ] while $str =~ /([ac])([bd])/g; print Dumper \@matches;