use strict;
my $str = '#if defined (_MSC_VER) && !defined(__clang__)
double pU0[3*4*K_MAX_STACK] __declspec(align(64));
#else
double pU0[3*4*K_MAX_STACK] __attribute__ ((aligned (64)));
#endif
#if defined (_MSC_VER) && !defined(__clang__)
double CC[16] __declspec(align(64)) = {0};
#else
double CC[16] __attribute__ ((aligned (64))) = {0};
#endif
#if defined (_MSC_VER) && !defined(__clang__)
double pU[3*4*K_MAX_STACK] __declspec(align(64));
#else
double pU[3*4*K_MAX_STACK] __attribute__ ((aligned (64)));
#endif';
my $regex = qr/\b(.*?])\s(__declspec.+?\)\))(.*?;)/mp;
my $subst = '$2 $1$3';
my $result = $str =~ s/$regex/$subst/rg;
print "The result of the substitution is' $result\n";
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html