#!/usr/bin/perl use strict; use warnings; my $script = ''; my $out = ''; my ($file) = @ARGV; while (<>) { next unless s/^(#\s*)//; $script .= $_ unless $. == 1; $out .= "$1$_"; } open STDOUT, '>', $file; print $out; open my $pipe, "| $ENV{SHELL}"; print $pipe $script; close $pipe;