my $foo = qr/foo/g; # hypothetical, won't work my $bar = qr/bar(\d+)/; while (<>) { while (/$foo$bar/) {...} # endless loop or not? my @x = /$foo$bar/; # what's the return value? s/$bar$foo/quz$1/; # replaces first or all matches? # ... etc. ... }