my $str = 'Hello World!'; # Alias $_ to $str. foreach ($str) { # Assumes each substitute operator is on a different line. while (defined(my $code = )) { eval($code) or die("Bad code at input line $.: $@\n"); } } print("$str\n"); # [hello world!] __DATA__ s/^/[/g s/$/]/g s/([A-Z])/lc($1)/eg