in reply to To find and replace in a file

I had replied earlier, but I think my post got reaped along with some other stuff as a result of a duplicate thread being started. Here again,
#!/usr/bin/perl use strict; use warnings; while (<DATA>) { chomp; $_ = "$2 $1" if ( /^(.+)(\[.+)/ ); #swap 2 parts if both exist print "logic $_\n"; } =Prints logic cfg_a logic [2:0] cfg_b logic [4:0] cfg_c logic cfg_d =cut __DATA__ cfg_a cfg_b[2:0] cfg_c[4:0] cfg_d
For more study, I recommend: http://www.perlmonks.org/index.pl/Tutorials#Pattern-Matching-Regular-Expressions-and-Parsing