#!usr/bin/perl use strict; use warnings; open( my $ip_fileh, '<', "D:\\PacketProcessor\\rtl\\common\\gen_sync_fifo.v" ) || die ( "unable to open the file D:\\PacketProcessor\\rtl\\common\\gen_sync_fifo.v\n" ); #open the file while (<$ip_fileh>) { #read the file line by line my $str = $_; #assign to a variable chomp $str; #remove the new line if ( $str =~ m/(Input|output) ((\w+(,\s*\w+)*)|([^\n]*))/i ) { my $type = $1; #get whether input or output my @inp_vals = split /\,\s*/, $2; #split by comma followed by space if more than one values local $" = "\n"; #to print the array values line by line print "$type\n@inp_vals \n"; #print the output } } __END__