#!/usr/bin/perl use strict; use warnings; my $input_file = "noname1.pl"; open INPUT, '<', "$input_file"; while (my $efile = ) { $efile =~ s/\$var\w \d+ ([!,\#,\",\$,\%,&]) (\w) \$end/\$var $1 $2/; print $efile; } close INPUT; __DATA__ $var , x $var ! _ $vary 3 # aa $end