http://www.perlmonks.org?node_id=374764


in reply to making my script work with vi

When you use ! with vi, it sends the text to the program on STDIN, and replaces it with whatever the program outputs on STDOUT. Try something like this:
#!/usr/bin/perl -w use strict; while (<STDIN>) { chomp; if ( ! -e ) { print "#$_\n"; } else { print "$_\n"; } }