#!perl use strict; use warnings; my $string = "I don't know what to do ** when I do this"; if ($string =~ /(.*?\*\*.*?)(\b[a-zA-Z']+\b)/) { print "Match <$2> at offset " . length($1) . $/; } else { print "No match" . $/; } my @chars = (split //, $2); @chars = @chars[0..9] if (@chars > 10); print join(' - ', @chars) . $/; __END__ OUTPUT: Match at offset 27 w - h - e - n