my @services = `systemctl list-unit-files`; if( my @smb = grep { /smb\.service/ } @services ) { my $fh = open_file( 'path1' ); print DATEI "chkconfig smb: OK\n"; print DATEI "Output:_\n " . join( "", @smb) . \n\n; };