I haven't written a Perl script for a long time. Recently, my computer has the prison break audio and SRT lyrics. However, the lyrics are incorrect. After the script is processed, you can change your voice to subtitles. It is mainly used to review Perl scripts, regular expressions, file reading, loops, conditions, etc #! /Usr/bin/perl # print 'done'; # my $ file = '<E: \ prison break1 \ Prison Break-1x02-Allen [Eng-subtitle]. srt'; # my $ out = '> E: \ prison break1 \ p02.srt'; # Open (file, $ file) or die "$! \ N "; # Open (result, $ out) or die $ !; My $ dirmp3andlrc = 'e: \ prison break1 '; # MP3 and LRC files are all in this folder. My $ dirlrctarget = 'e: \ Pb'; opendir (mp3_and_lrc, $ dirmp3andlrc) or die $ !; My @ MP3; # MP3 format my @ LRC; # LRC format my $ hashmp3; my $ hashlrc; while ($ file = readdir (mp3_and_lrc) {# $ I = 0; if ($ file = ~ /\. SRT $/) {# Push @ LRC, $ file; # Print $ file. "\ n"; my $ lyric = "<$ dirmp3andlrc \ $ file"; open (SRT, $ lyric) or die "$! \ N "; open (result,"> $ dirlrctarget \ $ file ") or die" $! \ N "; # print"> $ dirmp3 \ $ file \ n "; my $ Li; my @ final; my @ lines = <SRT>; for (my $ I = 0; $ I <@ lines; $ I ++) {$ line = $ lines [$ I]; # print 'before: I = '. $ I. '; V = '. $ line ;#. "\ n"; # $ Li. = $ li2; # print 'after: I = '. $ I. '; V = '. $ line ;#. "\ n"; # $ line = ~ S/[\ r \ n] //; if ($ line = ~ /(^ \ D)/or $ line = ~ /(^ $)/S) {#@ final [] = $ line; # print "tag \ n"; push @ final, $ line ;} else {# print "real = \ n"; my $ realwords = ''; my $ TMP; For ($ TMP = 0; $ TMP <@ lines; $ TMP ++) {# print't = '. $ TMP. "\ n"; # print 'v = '. $ lines [$ I + $ TMP]. "\ n"; if ($ lines [$ I + $ TMP] = ~ /(^ \ D)/or $ lines [$ I + $ TMP] = ~ /(^ $)/S) {last;} else {$ realwords. = $ lines [$ I + $ TMP]; }}$ I + = $ TMP; $ realwords = ~ S/\ N // G; push @ final, $ realwords. "\ n"; print 'realwords = '. $ realwords. "\ n" ;}# print 'line = '. $ Li; print result @ final; close (SRT); close (result) ;}}# foreach (@ LRC) {#$ name =$ _; # $ list = substr ($ name, 17, 2); # $ list = ~ S/^ 0 //; # $ name = ~ S /\. SRT $ //; # rename "$ dir \ $ listparts", "$ dir \ $ name1_"; # print" before modify: $ dir \ $ listparts, \ n \ nafter modify: $ dir \ $ name1_\ N ";#} closedir Pb; exit;