The perl -pie flags transform Perl into a powerful multi-file streaming search-and-replace editor.
Command Flag Meanings
perl -p -i -e 'code' file.txt
-p: Loop over input lines and print each line automatically (likesed).-i: Edit files in-place (overwriting original file). Use-i.bakto preserve backup copies.-e: Execute one line of Perl code.
Search & Replace Examples
Basic Global Substitution
# Replace 'hello' with 'world' across all .txt files
perl -p -i -e 's/hello/world/g' *.txt
With Backup Files
# Modifies original and saves original copy as file.txt.bak
perl -p -i.bak -e 's/foo/bar/g' file.txt
Regular Expressions & Backreferences
# Transform '@include align-items(center);' into 'align-items: center;'
perl -p -i -e 's/@include (align-items)\((.*)\);/$1: $2;/g' style.css