perl -Mstrict -wne'print "$1\n" while /\B(-I\S+)/g;' infile #### #!/usr/bin/perl -w use strict; while(<>) { print "$1\n" while /\B(-I\S+)/g; }