while ( $line =~ /\controller_name,\s+(\w+)/g ) { my $fourth = $1; print "$fourth"; } #### Win8 Strawberry 5.8.9.5 (32) Sat 05/22/2021 11:10:41 C:\@Work\Perl\monks >perl -Mstrict -Mwarnings my $line = "controller_name,bist_top_ctrl\n"; if ($line =~ /controller_name,\s*(\w+)/) { my $fourth = $1; print "'$fourth' \n"; } ^Z 'bist_top_ctrl'