use strict; use warnings; use Test::More tests => 1; my $str = '/a/b/c/d'; my $re = qr#^/a/b/([^/]*)/([^\/]*)#; my $want = "/a/b/\033[1;31mc\033[0m/\033[1;31md\033[0m"; my @caps = $str =~ $re; my $out = '/a/b/' . join '/', map {"\033[1;31m$_\033[0m"} @caps; is $out, $want, "Matched '$want'";