#!/usr/bin/perl use strict; use warnings; while () { chomp; $_ = "$2 $1" if ( /^(.+)(\[.+)/ ); #swaps 2 pieces if both found 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