#!/usr/bin/perl -w use strict; my $chars = <>; my $locs = join("", <>); my $out = ""; my $idx = 0; for(split//,$locs){ if(/#/){ $out .= substr($chars, $idx++, 1) }else{ $out .= $_ } } print($out)
Note that non-ascii characters in the above source code will be escaped (such as \x9f).