#!/usr/bin/perl $regex = qr/(?{print "Hey!";}).../; $string = "some word"; $string =~ s/some($regex)/$1 x 5/e; print $string,$/;