Your main loop
open(ITEMP,"/tmp/scresult.tmp");
@data=<ITEMP>;
close ITEMP;
foreach $x(@data)
{
if($x=~/^\(gdb\)/)
{
$x=~s/\(gdb\) 0x.+ <.+>:\s+//g;
$x=~s/0x/\\x/g;
$x=~s/\n//g;
$x=~s/\(gdb\)//g;
$x=~s/\s+//g;
$sc.=$x;
}
$i++;
#
# "Indent" the shellcode
# ($i exists only for this)
#
if(($i%12)==0)
{
$sc.="\"\n\t\""
}
}
is probably better written as:
open( TEMP, "</tmp/scresult.tmp" )
or die "Cannot open: $!\";
my $sc="char ".$func."[]=\n\t\"";
my $i = -1;
while (<TEMP>)
{
if(/^\(gdb\)/)
{
s/\(gdb\) 0x.+ <.+>:\s+//g;
s/0x/\\x/g;
s/\n//g;
s/\(gdb\)//g;
s/\s+//g;
$sc .= $_;
}
# "Indent" the shellcode
# ($i exists only for this)
$i++;
unless (++$i%12)
{
$sc.="\"\n\t\""
}
}
close TEMP;
Not only is it clearer what you're doing, but you don't slurp the whole file into memory. What if you're going for 1G of data? Also, you should indent your comments to line up with your code. Otherwise, the whole point of indenting - to show logical groupings - is ruined. When I skimmed your original code, I didn't immediately see the fact that the modulo-check on $i had something to do with the loop.
Plus, you shouldn't declare a variable until you intend to use it. You declare $sc way up at the top, but don't use it until nearly the end. If you declare it at the top, I'm going to look for usage near the top. If I don't see it, I'm going to start looking for bugs that may not be there.