use strict;
my $str = 'こんにちは
質問です
●Regular Expressionの使用環境
普通のテキストファイル
いま Sublime text を使ってますが無料のエディタなら何でも使います
●検索か置換か?
置換
●説明
各パラグラフの1行目を2行目以下の全ての行に加えたい
1行目はパラグラフごとに異なり、2行目以下はすべて異なる
●対象データ
/system/app
AntHalService
AutoRegistration
BasicDreams
/system/priv-app
AutoKillService
BackupRestoreConfirmation
●希望する結果
AntHalService^=/system/app/AntHalService
AutoRegistration^=/system/app/AutoRegistration
BasicDreams^=/system/app/BasicDreams
AutoKillService^=/system/priv-app/AutoKillService
BackupRestoreConfirmation^=/system/priv-app/BackupRestoreConfirmation
よろしくお願いします';
my $regex = qr/^(\/.*)\n(.+)\n*|(?<=^(\/.*)\n(?:.+\n)*)(.+)\n*/mp;
my $subst = '$2$4^=$1$3/$2$4\\n';
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