use strict; use warnings; open(my $in, '<', $ARGV[0]) or die "Unable to open for read: $!"; while (my $line = <$in>) { while ( $line =~ /\controller_name,\s+(\w+)/g ) { my $fourth = $1; print "$fourth"; } } close $in;