in reply to home work help

Sounds like a lot of work. Why not just:
my $cmd = <STDIN>; $cmd =~ tr/#\n/|/d; system($cmd);
Of course, I'm missing the original requirements.