[... some stuff here ] if ( $var eq "*" ) { $file = "name*"; # is some real file with an Asterix to search only on them in the real code my $ls = $sftp->ls (wanted => qr/$file}/ ) or die "unable to retrieve directory: ".$sftp->error; print "$_->{longname}\n" for (@$ls); } else { $file = "realname.ext"; # existing file say $file; # reading - default method - from the remote file $fh1 = $sftp->open("$file") or die $sftp->error; while (<$fh1>) { print if /ORA-/ || /Fehler/ || /ORACLE-Fehler/; # my $last = $_; # print $last; } exit 0;