while( ) { if( my $pos = index( $_, '--foo' ) ) { $pos += 5; print substr( $_, $pos, length($_) - $pos ); } }