in reply to Regex and writing lines in file

Perl regular expressions are powerful. This kind of activity would be considered obfuscation, though, and I would not recommend it for production code:
perl -pe 's/.*pattern\n$/<>for 1..3;$_/e'
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ