in reply to print the whole line

You code is working already.
use strict; use warnings; use Data::Dumper; my @mydata = qw/ abcd cabc abcdabcd defg xyz /; for(@mydata) { if($_ =~ /abc/g) { print "$_\n"; #print the line } }
And the output -
abcd cabc abcdabcd

I have a feeling that you want to do this with a one-liner instead? Which is already answered by BrowserUk.