#!/usr/bin/perl

# move shebang to the top
use strict;
use warnings;

# load the whole file
my $doc = do { local $/; <> };

# check if there is a shebang at the top

if ($doc =~ m{^#!/}) {
	# nothing to do
}
elsif ($doc =~ s{\n+(#!/.*?\n)\n*}{\n\n}s) {
	# move shebang to the top
	my $shebang = $1;
	$doc =~ s/^\n*/\n/s;
	$doc = $shebang . $doc;
}
else {
	# no shebang found
}

print $doc;
