in reply to Find and Replace

my declares a lexical variable in the current scope. Your program has the structure
if (...) { # you declare a variable here my $copy; ... # use it here } # and use it here - WRONG

You can't use the variable outside the block you declare it in. So move the declaration outside of the block.

Perl 6 - links to (nearly) everything that is Perl 6.