foreach my $line (@elements) { print "$$line
"; # you sure that you don't want this after the substitution? $$line=~s/'//g; }